<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="python,项目,">










<meta name="description" content="高效微信公众号历史文章和阅读数据爬虫1234#git clone https://github.com/wonderfulsuccess/weixin_crawler$ cd weixin_crawler/project/#https://github.com/24OI/OI-wiki/$ python(3) ./main.py 编程竞赛123456git clone https://git.de">
<meta name="keywords" content="python,项目">
<meta property="og:type" content="article">
<meta property="og:title" content="有用的Python项目收集">
<meta property="og:url" content="http://yoursite.com/2018/12/12/有用的Python项目收集/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:description" content="高效微信公众号历史文章和阅读数据爬虫1234#git clone https://github.com/wonderfulsuccess/weixin_crawler$ cd weixin_crawler/project/#https://github.com/24OI/OI-wiki/$ python(3) ./main.py 编程竞赛123456git clone https://git.de">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-11T09:26:57.124Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="有用的Python项目收集">
<meta name="twitter:description" content="高效微信公众号历史文章和阅读数据爬虫1234#git clone https://github.com/wonderfulsuccess/weixin_crawler$ cd weixin_crawler/project/#https://github.com/24OI/OI-wiki/$ python(3) ./main.py 编程竞赛123456git clone https://git.de">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/12/12/有用的Python项目收集/">



<meta name="referrer" content="never"> ​​​​


  <title>有用的Python项目收集 | 苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/12/有用的Python项目收集/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">有用的Python项目收集</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-12-12T14:09:33+08:00">
                2018-12-12
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  10.5k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  50 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="高效微信公众号历史文章和阅读数据爬虫"><a href="#高效微信公众号历史文章和阅读数据爬虫" class="headerlink" title="高效微信公众号历史文章和阅读数据爬虫"></a>高效微信公众号历史文章和阅读数据爬虫</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">#git clone https://github.com/wonderfulsuccess/weixin_crawler</span><br><span class="line">$ cd weixin_crawler/project/</span><br><span class="line">#https://github.com/24OI/OI-wiki/</span><br><span class="line">$ python(<span class="number">3</span>) ./main.py</span><br></pre></td></tr></table></figure>
<h3 id="编程竞赛"><a href="#编程竞赛" class="headerlink" title="编程竞赛"></a>编程竞赛</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">git clone https:<span class="comment">//git.dev.tencent.com/scaffrey/OI-wiki.git -b coding-pages</span></span><br><span class="line"># 如果是 python3</span><br><span class="line">python3 -m http.server</span><br><span class="line"># 如果是 python2</span><br><span class="line">python2 -m SimpleHTTPServer <span class="number">8888</span></span><br><span class="line"># 有些环境下找不到名叫 python3/python2 的可执行文件，不妨运行 python 试试</span><br></pre></td></tr></table></figure>
<h3 id="全网帮你抓取信息"><a href="#全网帮你抓取信息" class="headerlink" title="全网帮你抓取信息"></a>全网帮你抓取信息</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># clone the repo</span><br><span class="line">$ git clone https:<span class="comment">//github.com/TheYahya/sherlock.git</span></span><br><span class="line"></span><br><span class="line"># change the working directory to sherlock</span><br><span class="line">$ cd sherlock</span><br><span class="line"></span><br><span class="line"># install the requirements</span><br><span class="line">$ pip3 install -r requirements.txt</span><br><span class="line">$ python3 sherlock.py --help</span><br><span class="line">usage: sherlock.py [-h] [--version] [--verbose] [--quiet] [--tor]</span><br><span class="line">                   [--unique-tor] [--csv] [--site SITE_NAME]</span><br><span class="line">                   USERNAMES [USERNAMES ...]</span><br><span class="line"></span><br><span class="line">Sherlock: Find Usernames Across Social Networks (Version <span class="number">0.2</span><span class="number">.0</span>)</span><br></pre></td></tr></table></figure>
<h3 id="二维码"><a href="#二维码" class="headerlink" title="二维码"></a>二维码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">pip install qrcode</span><br><span class="line"><span class="keyword">import</span> qrcode</span><br><span class="line"></span><br><span class="line"># 二维码内容</span><br><span class="line">data = <span class="string">"https://www.baidu.com"</span></span><br><span class="line"># 生成二维码</span><br><span class="line">img = qrcode.make(data=data)</span><br><span class="line"># 直接显示二维码</span><br><span class="line">img.show()</span><br><span class="line"># 保存二维码为文件</span><br><span class="line"># img.save("baidu.jpg")</span><br><span class="line">pip install zxing</span><br><span class="line"><span class="keyword">import</span> zxing</span><br><span class="line"></span><br><span class="line">reader = zxing.BarCodeReader()</span><br><span class="line">barcode = reader.decode(<span class="string">"baidu.jpg"</span>)</span><br><span class="line">print(barcode.parsed)</span><br></pre></td></tr></table></figure>
<h3 id="本地区块链"><a href="#本地区块链" class="headerlink" title="本地区块链"></a>本地区块链</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//https://learnku.com/articles/23196</span></span><br><span class="line">pip install py-geth</span><br><span class="line">&gt;&gt;&gt; <span class="keyword">from</span> geth <span class="keyword">import</span> LiveGethProcess</span><br><span class="line">&gt;&gt;&gt; geth = LiveGethProcess()</span><br><span class="line">&gt;&gt;&gt; geth.start()</span><br><span class="line">&gt;&gt;&gt; geth = DevGethProcess(<span class="string">'testing'</span>, <span class="string">'/tmp/some-other-base-dir/'</span>)</span><br><span class="line">&gt;&gt;&gt; geth.start()</span><br></pre></td></tr></table></figure>
<h3 id="虚拟环境安装"><a href="#虚拟环境安装" class="headerlink" title="虚拟环境安装"></a>虚拟环境安装</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">pip intsall virtualenv </span><br><span class="line">pip install virtualenvwrapper-win  <span class="comment">//windows下</span></span><br><span class="line">pip install virtualenvwrapper  <span class="comment">//linux</span></span><br><span class="line">mkvirtualenv *envName*  <span class="comment">//创建一个虚拟环境 创建在用户家目录下</span></span><br><span class="line">workenon *envName*  <span class="comment">//激活环境</span></span><br><span class="line">rmvirtualenv *envName* <span class="comment">//删除环境</span></span><br><span class="line">deactivate  <span class="comment">//退出环境</span></span><br><span class="line">worken <span class="comment">//列出环境</span></span><br><span class="line">需要进入虚拟环境中，执行pip install即可</span><br></pre></td></tr></table></figure>
<h3 id="网易云音乐下载"><a href="#网易云音乐下载" class="headerlink" title="网易云音乐下载"></a>网易云音乐下载</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">$ pip3 install pymusic-dl</span><br><span class="line"></span><br><span class="line">$ music-dl --help</span><br><span class="line">Usage: music-dl [OPTIONS]</span><br><span class="line"></span><br><span class="line">  Search and download music <span class="keyword">from</span> netease, qq, kugou, baidu and xiami.</span><br><span class="line">  Example: music-dl -k <span class="string">"周杰伦"</span></span><br><span class="line"></span><br><span class="line">Options:</span><br><span class="line">  --version            Show the version and exit.</span><br><span class="line">  -k, --keyword TEXT   搜索关键字</span><br><span class="line">  -s, --source TEXT    数据源目前支持qq netease kugou baidu xiami flac</span><br><span class="line">  -c, --count INTEGER  搜索数量限制</span><br><span class="line">  -o, --outdir TEXT    指定输出目录</span><br><span class="line">  -x, --proxy TEXT     指定代理（如http:<span class="comment">//127.0.0.1:1087）</span></span><br><span class="line">  -m, --merge          对搜索结果去重和排序（默认不去重）</span><br><span class="line">  -v, --verbose        详细模式</span><br><span class="line">  --help               Show <span class="keyword">this</span> message and exit.</span><br><span class="line">  </span><br><span class="line">  λ music-dl -k <span class="string">'周杰伦'</span></span><br><span class="line">  </span><br><span class="line">  Searching <span class="string">'周杰伦'</span> <span class="keyword">from</span> ... QQ ... KUGOU ... NETEASE ... BAIDU ... XIAMI ...</span><br><span class="line">  ---------------------------</span><br><span class="line">  </span><br><span class="line">   [  <span class="number">0</span> ]      QQ | <span class="number">0</span>:<span class="number">03</span>:<span class="number">35</span> -  <span class="number">3.28</span>MB - 周杰伦 - 告白气球 - 周杰伦的床边故事</span><br><span class="line">   [  <span class="number">1</span> ]      QQ | <span class="number">0</span>:<span class="number">03</span>:<span class="number">59</span> -  <span class="number">3.66</span>MB - 周杰伦 - 青花瓷 - 我很忙</span><br><span class="line">   [  <span class="number">2</span> ]      QQ | <span class="number">0</span>:<span class="number">04</span>:<span class="number">29</span> -  <span class="number">4.12</span>MB - 周杰伦 - 晴天 - 叶惠美</span><br><span class="line">   [  <span class="number">3</span> ]      QQ | <span class="number">0</span>:<span class="number">05</span>:<span class="number">26</span> -  <span class="number">4.99</span>MB - 周杰伦 - 轨迹 (伴奏) - 寻找周杰伦</span><br><span class="line">   [  <span class="number">4</span> ]      QQ | <span class="number">0</span>:<span class="number">04</span>:<span class="number">16</span> -  <span class="number">3.92</span>MB - 周杰伦 - 说好的幸福呢 - 魔杰座</span><br><span class="line">   [  <span class="number">5</span> ]   KUGOU | <span class="number">0</span>:<span class="number">03</span>:<span class="number">35</span> -  <span class="number">3.28</span>MB - 周杰伦 - 告白气球 - 周杰伦的床边故事</span><br><span class="line">   [  <span class="number">6</span> ]   KUGOU | <span class="number">0</span>:<span class="number">04</span>:<span class="number">29</span> -  <span class="number">4.12</span>MB - 周杰伦 - 晴天 - 叶惠美</span><br><span class="line">   [  <span class="number">7</span> ]   KUGOU | <span class="number">0</span>:<span class="number">03</span>:<span class="number">57</span> -  <span class="number">3.62</span>MB - 周杰伦 - 青花瓷 - 我很忙</span><br><span class="line">   [  <span class="number">8</span> ]   KUGOU | <span class="number">0</span>:<span class="number">03</span>:<span class="number">43</span> -  <span class="number">3.41</span>MB - 周杰伦 - 稻香 - 魔杰座</span><br><span class="line">   [  <span class="number">9</span> ]   KUGOU | <span class="number">0</span>:<span class="number">04</span>:<span class="number">56</span> -  <span class="number">4.53</span>MB - 周杰伦 - 不能说的秘密 - 不能说的秘密 电影原声带</span><br><span class="line">   [ <span class="number">10</span> ] NETEASE | <span class="number">0</span>:<span class="number">03</span>:<span class="number">12</span> -  <span class="number">2.21</span>MB - 周杰伦、李玟 - 刀马旦 - Partners 拍档</span><br><span class="line">   [ <span class="number">11</span> ]   BAIDU | <span class="number">0</span>:<span class="number">04</span>:<span class="number">28</span> - <span class="number">22.38</span>MB - 山弟 - 周杰伦 - 周杰伦</span><br><span class="line">   [ <span class="number">12</span> ]   BAIDU | <span class="number">0</span>:<span class="number">03</span>:<span class="number">35</span> -  <span class="number">3.29</span>MB - 周杰伦 - 告白气球 - 周杰伦的床边故事</span><br><span class="line">   [ <span class="number">13</span> ]   BAIDU | <span class="number">0</span>:<span class="number">03</span>:<span class="number">59</span> -  <span class="number">3.65</span>MB - 周杰伦 - 青花瓷 - 我很忙</span><br><span class="line">   [ <span class="number">14</span> ]   BAIDU | <span class="number">0</span>:<span class="number">04</span>:<span class="number">30</span> -  <span class="number">4.14</span>MB - 周杰伦 - 简单爱 - 婚礼歌手 幸福情歌精选</span><br><span class="line">   [ <span class="number">15</span> ]   BAIDU | <span class="number">0</span>:<span class="number">03</span>:<span class="number">46</span> -  <span class="number">3.46</span>MB - 周杰伦 - 夜曲 - 十一月的萧邦</span><br><span class="line">   [ <span class="number">16</span> ]   XIAMI | <span class="number">0</span>:<span class="number">03</span>:<span class="number">40</span> -  <span class="number">3.61</span>MB - 张学友 - 星晴 (Live) - 活出生命Live演唱会</span><br><span class="line">   [ <span class="number">17</span> ]   XIAMI | <span class="number">0</span>:<span class="number">03</span>:<span class="number">15</span> -  <span class="number">2.98</span>MB - Abby - 周杰伦香水广告BGM - 周杰伦香水广告</span><br><span class="line">   [ <span class="number">18</span> ]   XIAMI | <span class="number">0</span>:<span class="number">04</span>:<span class="number">08</span> -   <span class="number">9.5</span>MB - G.E.M.邓紫棋 - 龙卷风 - 龙卷风</span><br><span class="line">   [ <span class="number">19</span> ]   XIAMI | <span class="number">0</span>:<span class="number">04</span>:<span class="number">34</span> -  <span class="number">4.19</span>MB - 鲁瑾 - 周杰伦：夜曲 - 二十年的青春和往昔第五季 这一刻你依然如此动人</span><br><span class="line">   [ <span class="number">20</span> ]   XIAMI | <span class="number">0</span>:<span class="number">03</span>:<span class="number">16</span> -  <span class="number">2.99</span>MB - Abby - 周杰伦香水广告单曲（升key） - 周杰伦香水广告</span><br><span class="line">  </span><br><span class="line">  ---------------------------</span><br><span class="line">  请输入下载序号，支持形如 <span class="number">0</span> <span class="number">3</span><span class="number">-5</span> <span class="number">8</span> 的格式，输入 N 跳过下载</span><br></pre></td></tr></table></figure>
<h3 id="股票行情"><a href="#股票行情" class="headerlink" title="股票行情"></a>股票行情</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">pip instasll tushare</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> tushare <span class="keyword">as</span> ts</span><br><span class="line">ts.set_token(<span class="string">'你的token'</span>)</span><br><span class="line">pro = ts.pro_api()</span><br><span class="line">data = pro.stock_basic(exchange_id=<span class="string">''</span>, is_hs=<span class="string">''</span>, fields=<span class="string">'symbol,name,is_hs,list_date,list_status'</span>)</span><br><span class="line">print(data)</span><br><span class="line"># ''表示获取全部https://www.makcyun.top/python_data_analysis01.html </span><br><span class="line">data = data.set_index(data[<span class="string">'list_date'</span>])</span><br><span class="line">data = data[<span class="string">'2017'</span>]</span><br><span class="line">print(data.head())</span><br><span class="line"># 结果</span><br><span class="line">              ts_code  symbol  name list_status  list_date is_hs</span><br><span class="line">list_date                                                       </span><br><span class="line"><span class="number">2017</span><span class="number">-12</span><span class="number">-25</span>  <span class="number">001965.</span>SZ  <span class="number">001965</span>  招商公路           L <span class="number">2017</span><span class="number">-12</span><span class="number">-25</span>     S</span><br><span class="line"><span class="number">2017</span><span class="number">-03</span><span class="number">-24</span>  <span class="number">002774.</span>SZ  <span class="number">002774</span>  快意电梯           L <span class="number">2017</span><span class="number">-03</span><span class="number">-24</span>     N</span><br><span class="line"><span class="number">2017</span><span class="number">-01</span><span class="number">-12</span>  <span class="number">002824.</span>SZ  <span class="number">002824</span>  和胜股份           L <span class="number">2017</span><span class="number">-01</span><span class="number">-12</span>     N</span><br><span class="line"><span class="number">2017</span><span class="number">-01</span><span class="number">-06</span>  <span class="number">002838.</span>SZ  <span class="number">002838</span>  道恩股份           L <span class="number">2017</span><span class="number">-01</span><span class="number">-06</span>     N</span><br><span class="line"><span class="number">2017</span><span class="number">-01</span><span class="number">-24</span>  <span class="number">002839.</span>SZ  <span class="number">002839</span>  张家港行           L <span class="number">2017</span><span class="number">-01</span><span class="number">-24</span>     S</span><br></pre></td></tr></table></figure>
<h3 id="使用python生成微信好友地域分析"><a href="#使用python生成微信好友地域分析" class="headerlink" title="使用python生成微信好友地域分析"></a>使用python生成微信好友地域分析</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br></pre></td><td class="code"><pre><span class="line"># -*- coding: UTF-8 -*-</span><br><span class="line"><span class="keyword">from</span> wxpy <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> wxpy <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> os <span class="keyword">import</span> path</span><br><span class="line"><span class="keyword">import</span> re, jieba</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">from</span> wordcloud <span class="keyword">import</span> WordCloud,ImageColorGenerator</span><br><span class="line"><span class="keyword">import</span> matplotlib.font_manager <span class="keyword">as</span> fm</span><br><span class="line"># 初始化一个机器人对象https://zhuanlan.zhihu.com/p/60723803</span><br><span class="line"># cache_path缓存路径，给定值为第一次登录生成的缓存文件路径</span><br><span class="line">bot = Bot()</span><br><span class="line">#获取好友列表(包括自己)</span><br><span class="line">my_friends = bot.friends(update=False)</span><br><span class="line"><span class="string">''</span><span class="string">'</span></span><br><span class="line"><span class="string">stats_text 函数：帮助我们简单统计微信好友基本信息</span></span><br><span class="line"><span class="string">简单的统计结果的文本</span></span><br><span class="line"><span class="string">    :param total: 总体数量</span></span><br><span class="line"><span class="string">    :param sex: 性别分布</span></span><br><span class="line"><span class="string">    :param top_provinces: 省份分布</span></span><br><span class="line"><span class="string">    :param top_cities: 城市分布</span></span><br><span class="line"><span class="string">    :return: 统计结果文本</span></span><br><span class="line"><span class="string">'</span><span class="string">''</span></span><br><span class="line">print(my_friends.stats_text())</span><br><span class="line"># 清洗数据，生成词云图</span><br><span class="line">#获取当前的项目文件加的路径</span><br><span class="line">#读取停用词表</span><br><span class="line">stopwords_path=<span class="string">'static/stopwords.txt'</span></span><br><span class="line"></span><br><span class="line">#定义个函数式用于分词</span><br><span class="line">def jiebaclearText(text):</span><br><span class="line">    #定义一个空的列表，将去除的停用词的分词保存</span><br><span class="line">    mywordList=[]</span><br><span class="line">    #进行分词</span><br><span class="line">    seg_list=jieba.cut(text,cut_all=False)</span><br><span class="line">    #将一个generator的内容用/连接</span><br><span class="line">    listStr=<span class="string">'/'</span>.join(seg_list)</span><br><span class="line">    listStr = listStr.replace(<span class="string">"class"</span>,<span class="string">""</span>)</span><br><span class="line">    listStr = listStr.replace(<span class="string">"span"</span>, <span class="string">""</span>)</span><br><span class="line">    listStr = listStr.replace(<span class="string">"emoji"</span>, <span class="string">""</span>)</span><br><span class="line">    #打开停用词表</span><br><span class="line">    f_stop=open(stopwords_path,encoding=<span class="string">"utf8"</span>)</span><br><span class="line">    #读取</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        f_stop_text=f_stop.read()</span><br><span class="line">    <span class="keyword">finally</span>:</span><br><span class="line">        f_stop.close()#关闭资源</span><br><span class="line">    #将停用词格式化，用\n分开，返回一个列表</span><br><span class="line">    f_stop_seg_list=f_stop_text.split(<span class="string">"\n"</span>)</span><br><span class="line">    #对默认模式分词的进行遍历，去除停用词</span><br><span class="line">    <span class="keyword">for</span> myword <span class="keyword">in</span> listStr.split(<span class="string">'/'</span>):</span><br><span class="line">        #去除停用词</span><br><span class="line">        <span class="keyword">if</span> not(myword.split()) <span class="keyword">in</span> f_stop_seg_list and len(myword.strip())&gt;<span class="number">1</span>:</span><br><span class="line">            mywordList.append(myword)</span><br><span class="line">    <span class="keyword">return</span> <span class="string">' '</span>.join(mywordList)</span><br><span class="line"># 生成词云图</span><br><span class="line">def make_wordcloud(text1,i):</span><br><span class="line">	bg = plt.imread(r<span class="string">"image/heart.jpg"</span>)</span><br><span class="line">	# 生成</span><br><span class="line">	wc = WordCloud(# FFFAE3</span><br><span class="line">		background_color="#FFFFFF",  # 设置背景为白色，默认为黑色</span><br><span class="line">		width=990,  # 设置图片的宽度</span><br><span class="line">		height=440,  # 设置图片的高度</span><br><span class="line">		mask=bg,</span><br><span class="line">		margin=10,  # 设置图片的边缘</span><br><span class="line">		max_font_size=70,  # 显示的最大的字体大小</span><br><span class="line">		random_state=20,  # 为每个单词返回一个PIL颜色</span><br><span class="line">		font_path='static/simkai.ttf'  # 中文处理，用系统自带的字体</span><br><span class="line">	).generate(text1)</span><br><span class="line">	# 为图片设置字体</span><br><span class="line">	my_font = fm.FontProperties(fname=<span class="string">'static/simkai.ttf'</span>)</span><br><span class="line">	# 图片背景</span><br><span class="line">	bg_color = ImageColorGenerator(bg)</span><br><span class="line">	# 开始画图</span><br><span class="line">	plt.imshow(wc.recolor(color_func=bg_color))</span><br><span class="line">	# 为云图去掉坐标轴</span><br><span class="line">	plt.axis(<span class="string">"off"</span>)</span><br><span class="line">	# 画云图，显示</span><br><span class="line">	# 保存云图</span><br><span class="line">	wc.to_file(r<span class="string">"image/render_0%d.png"</span>%i)</span><br><span class="line"># 微信昵称</span><br><span class="line">nick_name = <span class="string">''</span></span><br><span class="line"># 微信个性签名</span><br><span class="line">wx_signature = <span class="string">''</span></span><br><span class="line"><span class="keyword">for</span> friend <span class="keyword">in</span> my_friends:</span><br><span class="line">	# 微信昵称：NickName</span><br><span class="line">	nick_name = nick_name + friend.raw[<span class="string">'NickName'</span>]</span><br><span class="line">	# 个性签名：Signature</span><br><span class="line">	wx_signature = wx_signature + friend.raw[<span class="string">'Signature'</span>]</span><br><span class="line"></span><br><span class="line">nick_name = jiebaclearText(nick_name)</span><br><span class="line">wx_signature = jiebaclearText(wx_signature)</span><br><span class="line">make_wordcloud(nick_name,<span class="number">1</span>)</span><br><span class="line">make_wordcloud(wx_signature,<span class="number">2</span>)</span><br></pre></td></tr></table></figure>
<h3 id="检测微信好友是否把你删除"><a href="#检测微信好友是否把你删除" class="headerlink" title="检测微信好友是否把你删除"></a>检测微信好友是否把你删除</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">通过Pyhton登录网页版微信，给你所有好友发送 జ్ఞా 这个特殊符号，由于微信的bug，对方收不到这个特殊符号，只要有人删了你，你的微信对话页面就会显示对方已经把你删除发送失败。</span><br><span class="line">pip install itchat</span><br><span class="line"><span class="keyword">import</span> itchat</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line">  </span><br><span class="line">  </span><br><span class="line">itchat.auto_login(hotReload=True) # 热加载</span><br><span class="line">  </span><br><span class="line">print(<span class="string">'检测结果可能会引起不适。'</span>)</span><br><span class="line">print(<span class="string">'检测结果请在手机上查看，此处仅显示检测信息。'</span>)</span><br><span class="line">print(<span class="string">'消息被拒收为被拉黑， 需要发送验证信息为被删。'</span>)</span><br><span class="line">print(<span class="string">'没有结果就是好结果。'</span>)</span><br><span class="line">print(<span class="string">'检测1000位好友需要34分钟， 以此类推。'</span>)</span><br><span class="line">print(<span class="string">'为了你的账号安全着想，这个速度刚好。'</span>)</span><br><span class="line">print(<span class="string">'在程序运行期间请让程序保持运行，网络保持连接。'</span>)</span><br><span class="line">print(<span class="string">'请不要从手机端手动退出。'</span>)</span><br><span class="line">input(<span class="string">'按ENTER键继续...'</span>)</span><br><span class="line">  </span><br><span class="line">  </span><br><span class="line">friends = itchat.get_friends(update=True)</span><br><span class="line">lenght = len(friends)</span><br><span class="line">  </span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>, lenght):</span><br><span class="line">    # 微信bug，用自己账户给所有好友发送"ॣ ॣ ॣ"消息，当添加自己为好友时，只有自己能收到此信息，如果没添加自己为好友\</span><br><span class="line">    # 没有人能收到此信息，笔者此刻日期为2019/1/6 8:30，到目前为止微信bug还没修复。</span><br><span class="line">    # 所以迭代从除去自己后的第二位好友开始 range(1, lenght)。</span><br><span class="line">    itchat.send(<span class="string">"జ్ఞా"</span>, toUserName=friends[i][<span class="string">'UserName'</span>])</span><br><span class="line">    print(f<span class="string">'检测到第&#123;i&#125;位好友: &#123;str(friends[i]["NickName"]).center(20, " ")&#125;'</span>)</span><br><span class="line">    # 发送信息速度过快会被微信检测到异常行为。https://www.qingwei.tech/programe-develops/python/1268.html</span><br><span class="line">    time.sleep(<span class="number">2</span>)</span><br><span class="line">  </span><br><span class="line">print(<span class="string">'已检测完毕，请在手机端查看结果。'</span>)</span><br><span class="line">  </span><br><span class="line">  </span><br><span class="line">itchat.run()</span><br></pre></td></tr></table></figure>
<h3 id="分析你的微信好友签名"><a href="#分析你的微信好友签名" class="headerlink" title="分析你的微信好友签名"></a>分析你的微信好友签名</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> itchat</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"><span class="keyword">import</span> jieba</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">from</span> wordcloud <span class="keyword">import</span> WordCloud, ImageColorGenerator</span><br><span class="line">from scipy.misc import imread  # 这是一个处理图像的函数https://juejin.im/post/5ca4c7d7f265da30d34ba228</span><br><span class="line"></span><br><span class="line"># -*- coding: utf-8 -*-</span><br><span class="line"></span><br><span class="line">#导入模块</span><br><span class="line"><span class="keyword">from</span> wxpy <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"><span class="string">''</span><span class="string">'</span></span><br><span class="line"><span class="string">微信机器人登录有3种模式，</span></span><br><span class="line"><span class="string">(1)极简模式:robot = Bot()</span></span><br><span class="line"><span class="string">(2)终端模式:robot = Bot(console_qr=True)</span></span><br><span class="line"><span class="string">(3)缓存模式(可保持登录状态):robot = Bot(cache_path=True)</span></span><br><span class="line"><span class="string">'</span><span class="string">''</span></span><br><span class="line">#初始化机器人，选择缓存模式（扫码）登录</span><br><span class="line">robot = Bot(cache_path=True)</span><br><span class="line"></span><br><span class="line">#获取好友、群、公众号信息</span><br><span class="line">robot.chats()</span><br><span class="line"></span><br><span class="line">#获取好友的统计信息</span><br><span class="line">Friends = robot.friends()</span><br><span class="line">print(Friends.stats_text())</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">sign_list=[]</span><br><span class="line">itchat.auto_login(hotReload=True)</span><br><span class="line">itchat.send(u<span class="string">'Hello,world'</span>,<span class="string">'filehelper'</span>)</span><br><span class="line">friends = itchat.get_friends(update=True)[<span class="number">0</span>:]</span><br><span class="line">print(<span class="string">'开始获取微信好友个性签名.....'</span>)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> friends:</span><br><span class="line">    signature = i["Signature"].strip().replace("span", "").replace("class", "").replace("emoji", "") #过滤掉表情</span><br><span class="line">    #rep = re.compile("&lt; =.+/&gt;")</span><br><span class="line">    rep = re.compile(<span class="string">"[^\u4e00-\u9fa5^]"</span>)</span><br><span class="line">    nickName=i[<span class="string">"NickName"</span>]</span><br><span class="line">    signature = rep.sub(<span class="string">""</span>, signature)</span><br><span class="line">    sign_list.append(signature)</span><br><span class="line"></span><br><span class="line">text=<span class="string">''</span>.join(sign_list)</span><br><span class="line">wordlist_jieba = jieba.cut(text, cut_all=True)</span><br><span class="line">wl_space_split = <span class="string">' '</span>.join(wordlist_jieba)</span><br><span class="line"></span><br><span class="line">back_color = imread(<span class="string">'./mao.jpg'</span>)</span><br><span class="line"></span><br><span class="line"># 词云</span><br><span class="line">my_wordcloud = WordCloud(</span><br><span class="line">    background_color='white',  # 背景颜色</span><br><span class="line">    max_words=2000,  # 最大词数</span><br><span class="line">    mask=back_color,  # 以该参数值作图绘制词云，这个参数不为空时，width和height会被忽略</span><br><span class="line">    max_font_size=100,  # 显示字体的最大值</span><br><span class="line">    font_path='C:/Windows/Fonts/simfang.ttf',  # 指定字体文件 解决显示口字型乱码问题，</span><br><span class="line">    random_state=42,  # 为每个词返回一个PIL颜色</span><br><span class="line">    )</span><br><span class="line"></span><br><span class="line"># 用wl_space_split生成词云</span><br><span class="line">my_wordcloud.generate(wl_space_split)</span><br><span class="line"></span><br><span class="line"># 基于彩色图像 生成响应的色彩</span><br><span class="line">image_colors = ImageColorGenerator(back_color)</span><br><span class="line"># 显示图片</span><br><span class="line"># plt.imshow(my_wordcloud)</span><br><span class="line"># 关闭坐标轴</span><br><span class="line"># plt.axis('off')</span><br><span class="line"># 绘制词云</span><br><span class="line">plt.figure()</span><br><span class="line">plt.imshow(my_wordcloud.recolor(color_func=image_colors))</span><br><span class="line">plt.axis(<span class="string">'off'</span>)</span><br><span class="line"># 保存图片</span><br><span class="line">my_wordcloud.to_file(<span class="string">'ciyun.png'</span>)</span><br></pre></td></tr></table></figure>
<h3 id="处理-Python-中的时区"><a href="#处理-Python-中的时区" class="headerlink" title="处理 Python 中的时区"></a>处理 Python 中的时区</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">pip install pytz</span><br><span class="line">&gt;&gt;&gt; <span class="keyword">from</span> datetime <span class="keyword">import</span> datetime, timedelta</span><br><span class="line">&gt;&gt;&gt; <span class="keyword">from</span> pytz <span class="keyword">import</span> timezone</span><br><span class="line">&gt;&gt;&gt; <span class="keyword">import</span> pytz</span><br><span class="line">&gt;&gt;&gt; utc = pytz.utc</span><br><span class="line">&gt;&gt;&gt; utc.zone</span><br><span class="line"><span class="string">'UTC'</span></span><br><span class="line">&gt;&gt;&gt; beijing = timezone(<span class="string">'Asia/Shanghai'</span>)</span><br><span class="line">&gt;&gt;&gt; beijing.zone</span><br><span class="line"><span class="string">'Asia/Shanghai'</span></span><br><span class="line">&gt;&gt;&gt; tokyo = timezone(<span class="string">'Asia/Tokyo'</span>)</span><br><span class="line">&gt;&gt;&gt; tokyo.zone</span><br><span class="line"><span class="string">'Asia/Tokyo'</span></span><br><span class="line">第一种是使用pytz库提供的 localize() 方法。这用于本地化一个没有时区信息的日期时间:</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; fmt = <span class="string">'%Y-%m-%d %H:%M:%S %Z%z'</span></span><br><span class="line">&gt;&gt;&gt; loc_dt = beijing.localize(datetime(<span class="number">2018</span>, <span class="number">10</span>, <span class="number">27</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">0</span>))</span><br><span class="line">&gt;&gt;&gt; print(loc_dt.strftime(fmt))</span><br><span class="line"><span class="string">'2018-10-27 06:00:00 CST+0800'</span></span><br><span class="line"></span><br><span class="line">第二种方法是使用标准 astimezone() 方法转换现有的本地化时间：</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; jp_dt = loc_dt.astimezone(tokyo)</span><br><span class="line">&gt;&gt;&gt; jp_dt.strftime(fmt)</span><br><span class="line"><span class="string">'2018-10-27 07:00:00 JST+0900'</span></span><br><span class="line">处理时间的首选方法是始终以UTC工作，仅在生成输出以供人类读取时转换为本地时间:</span><br><span class="line">&gt;&gt;&gt; utc_dt = datetime(<span class="number">2018</span>, <span class="number">10</span>, <span class="number">27</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">0</span>, tzinfo=utc)</span><br><span class="line">&gt;&gt;&gt; loc_dt = utc_dt.astimezone(beijing)</span><br><span class="line">&gt;&gt;&gt; loc_dt.strftime(fmt)</span><br><span class="line"><span class="string">'2018-10-27 14:00:00 CST+0800'</span></span><br><span class="line">此库还允许使用本地时间进行日期算术，例如计算北京和东京的时差：</span><br><span class="line">&gt;&gt;&gt; timestamp = datetime.utcnow()</span><br><span class="line">&gt;&gt;&gt; dt_cn = beijing.localize(timestamp)</span><br><span class="line">&gt;&gt;&gt; dt_jp =tokyo.localize(timestamp)</span><br><span class="line">&gt;&gt;&gt; x = dt_cn - dt_jp</span><br><span class="line">&gt;&gt;&gt; int(x.total_seconds()/<span class="number">3600</span>)</span><br><span class="line"><span class="number">1</span></span><br></pre></td></tr></table></figure>
<h3 id="Python生成微信好友位置分布图"><a href="#Python生成微信好友位置分布图" class="headerlink" title="Python生成微信好友位置分布图"></a>Python生成微信好友位置分布图</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> itchat</span><br><span class="line"><span class="keyword">from</span> pyecharts <span class="keyword">import</span> <span class="built_in">Map</span></span><br><span class="line"></span><br><span class="line">#http://shuaiguoer.com/%E5%BE%AE%E4%BF%A1%E5%A5%BD%E5%8F%8B%E4%BD%8D%E7%BD%AE%E5%88%86%E5%B8%83%E5%9B%BE/</span><br><span class="line">List = []</span><br><span class="line">a = &#123;&#125;</span><br><span class="line">name = []</span><br><span class="line">value = []</span><br><span class="line"># 登录微信</span><br><span class="line">itchat.login()</span><br><span class="line"># 获取所有好友信息</span><br><span class="line">owner = itchat.get_friends()</span><br><span class="line"># 获取所有好友的所在位置</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> owner:</span><br><span class="line">    province = i[<span class="string">'Province'</span>]</span><br><span class="line">    List.append(province)</span><br><span class="line"># 获取每个位置对应的好友人数</span><br><span class="line"><span class="keyword">for</span> s <span class="keyword">in</span> List:</span><br><span class="line">    <span class="keyword">if</span> List.count(s) &gt;= <span class="number">1</span>:</span><br><span class="line">        a[s] = List.count(s)</span><br><span class="line"># 把去重后的位置添加到列表name中</span><br><span class="line"><span class="keyword">for</span> j <span class="keyword">in</span> a:</span><br><span class="line">    name.append(j)</span><br><span class="line"># 把每个位置对应的好友人数添加到列表values中</span><br><span class="line"><span class="keyword">for</span> v <span class="keyword">in</span> a.values():</span><br><span class="line">    value.append(v)</span><br><span class="line"># 生成地图</span><br><span class="line">maps = Map('微信好友位置分布图', width=1500, height=900)     # 设置地图的宽和高</span><br><span class="line"># 把数据添加到地图中</span><br><span class="line">maps.add(<span class="string">''</span>, name, value, maptype=<span class="string">'china'</span>, is_visualmap=True, visual_text_color=<span class="string">'#000'</span>, is_label_show=True, visual_range=[<span class="number">0</span>, <span class="number">20</span>])</span><br><span class="line"># is_visualmap        ---&gt;    是否使用视觉映射组件</span><br><span class="line"># visual_text_color   ---&gt;    两端文本颜色</span><br><span class="line"># is_label_show       ---&gt;    是否正常显示标签。标签即各点的数据项信息</span><br><span class="line"># visual_range        ---&gt;    指定允许的最小值与最大值</span><br><span class="line">maps.render('微信好友位置分布图.html')       # 生成HTML文件</span><br></pre></td></tr></table></figure>
<h3 id="图灵机器人与指定的好友微信聊天"><a href="#图灵机器人与指定的好友微信聊天" class="headerlink" title="图灵机器人与指定的好友微信聊天"></a>图灵机器人与指定的好友微信聊天</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> itchat</span><br><span class="line"><span class="keyword">import</span> http.client</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"> </span><br><span class="line"># 监听人的微信id</span><br><span class="line">touserNameId = <span class="string">'@becc4377a98a6df74fafc1192a3dd045'</span></span><br><span class="line">fromuserId=<span class="string">'d3aef9a75e2b51430683ffeb386f0564'</span></span><br><span class="line">tulingDomain=<span class="string">'openapi.tuling123.com'</span></span><br><span class="line">tulingOpenapiUrl=<span class="string">'http://'</span>+ tulingDomain + <span class="string">'/openapi/api/v2'</span></span><br><span class="line"># 聊天计数</span><br><span class="line">count= <span class="number">0</span></span><br><span class="line"> </span><br><span class="line"># 监听接收到的文件信息</span><br><span class="line">@itchat.msg_register(itchat.content.TEXT)</span><br><span class="line">def reply_msg(msg):</span><br><span class="line"> </span><br><span class="line">    print(msg)</span><br><span class="line">    # 指定好友回复特定消息</span><br><span class="line">    <span class="keyword">if</span> msg[<span class="string">'FromUserName'</span>] == touserNameId and msg[<span class="string">'ToUserName'</span>] == touserNameId:</span><br><span class="line"> </span><br><span class="line">        global count</span><br><span class="line"> </span><br><span class="line">        # 图灵机器人</span><br><span class="line">        robbot0 = <span class="string">'appkey0'</span></span><br><span class="line">        # 图灵机器人1</span><br><span class="line">        robbot1 = <span class="string">'appkey1'</span></span><br><span class="line">        # 图灵机器人2</span><br><span class="line">        robbot2 = <span class="string">'appkey2'</span></span><br><span class="line">        # 图灵机器人3</span><br><span class="line">        robbot3 = <span class="string">'appkey3'</span></span><br><span class="line">        # 图灵机器人4</span><br><span class="line">        robbot4 = <span class="string">'appkey4'</span></span><br><span class="line"> </span><br><span class="line">        count += <span class="number">1</span></span><br><span class="line">        temp= <span class="string">'robbot'</span>+ str(count<span class="comment">//98)</span></span><br><span class="line">        usedRobbot =locals()[temp]</span><br><span class="line">        print(<span class="string">"收到："</span>, msg.text)</span><br><span class="line">        info = msg.text</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line">        headers = &#123;</span><br><span class="line">            # heard部分直接通过chrome部分request header部分</span><br><span class="line">            <span class="string">'Accept'</span>: <span class="string">'application/json, text/plain, */*'</span>,</span><br><span class="line">            <span class="string">'Accept-Encoding'</span>: <span class="string">'gzip, deflate'</span>,</span><br><span class="line">            <span class="string">'Accept-Language'</span>: <span class="string">'zh-CN,zh;q=0.8'</span>,</span><br><span class="line">            <span class="string">'Connection'</span>: <span class="string">'keep-alive'</span>,</span><br><span class="line">            'Content-Length': '14',  # get方式提交的数据长度，如果是post方式，转成get方式：【id=wdb&amp;pwd=wdb】</span><br><span class="line">            <span class="string">'Content-Type'</span>: <span class="string">'application/x-www-form-urlencoded'</span>,</span><br><span class="line">            <span class="string">'Referer'</span>: <span class="string">'http://10.1.2.151/'</span>,</span><br><span class="line">            <span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36'</span></span><br><span class="line">        &#125;</span><br><span class="line">        data = &#123;</span><br><span class="line">	        <span class="string">"reqType"</span>:<span class="number">0</span>,</span><br><span class="line">             <span class="string">"perception"</span>: &#123;</span><br><span class="line">                <span class="string">"inputText"</span>: &#123;</span><br><span class="line">                    <span class="string">"text"</span>: info</span><br><span class="line">                &#125;,</span><br><span class="line">                <span class="string">"selfInfo"</span>: &#123;</span><br><span class="line">                    <span class="string">"location"</span>: &#123;</span><br><span class="line">                        <span class="string">"city"</span>: <span class="string">"北京"</span>,</span><br><span class="line">                        <span class="string">"province"</span>: <span class="string">"北京"</span>,</span><br><span class="line">                        <span class="string">"street"</span>: <span class="string">"信息路"</span></span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">             &#125;,</span><br><span class="line">            <span class="string">"userInfo"</span>: &#123;</span><br><span class="line">                <span class="string">"apiKey"</span>: usedRobbot,</span><br><span class="line">                <span class="string">"userId"</span>: <span class="string">"me"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        # 这里是为了找到 id 包含 FromUserName 和 ToUserName</span><br><span class="line">        print(data)</span><br><span class="line">        conn = http.client.HTTPConnection(tulingDomain)</span><br><span class="line">        header = &#123;<span class="string">"Content-type"</span>: <span class="string">"application/json"</span>&#125;</span><br><span class="line">        conn.request(method=<span class="string">"POST"</span>, url=tulingOpenapiUrl, headers=header, body=json.dumps(data))</span><br><span class="line">        response = conn.getresponse()</span><br><span class="line">        # print(response.status)</span><br><span class="line">        # print(response.reason)</span><br><span class="line">        res = response.read()</span><br><span class="line">        # print(res)</span><br><span class="line">        resp = json.loads(res)</span><br><span class="line">        #print(resp)</span><br><span class="line">        #print(type(resp))</span><br><span class="line"> </span><br><span class="line">        reponseType = resp[<span class="string">'results'</span>][<span class="number">0</span>][<span class="string">'values'</span>]</span><br><span class="line">        print(reponseType)</span><br><span class="line">        print(type(reponseType))</span><br><span class="line"> </span><br><span class="line">        #str = input("回复：")</span><br><span class="line">        itchat.send(reponseType[<span class="string">'text'</span>],toUserName=touserNameId)</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    # 退出程序以后还暂存登录状态 https://blog.csdn.net/yan88888888888888888/article/details/89373626</span><br><span class="line">    itchat.auto_login(hotReload=True)</span><br><span class="line"> </span><br><span class="line">    # 给文件助手发消息</span><br><span class="line">    itchat.send(<span class="string">"文件助手你好哦"</span>, toUserName=<span class="string">"filehelper"</span>)</span><br><span class="line">    itchat.run()</span><br></pre></td></tr></table></figure>
<h3 id="图灵机器人回复微信"><a href="#图灵机器人回复微信" class="headerlink" title="图灵机器人回复微信"></a>图灵机器人回复微信</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> wxpy <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> wx_friend</span><br><span class="line"></span><br><span class="line"># 微信机器人，缓存登录信息</span><br><span class="line">bot = Bot(cache_path=True)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">@bot.register(msg_types=FRIENDS)</span><br><span class="line">def auto_reply(msg):</span><br><span class="line">    <span class="string">""</span><span class="string">"自动接受好友请求"</span><span class="string">""</span></span><br><span class="line">    wx_friend.auto_accept_friends(msg)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">@bot.register(chats=Friend)</span><br><span class="line">def auto_reply(msg):</span><br><span class="line">    <span class="string">""</span><span class="string">"自动回复好友"</span><span class="string">""</span></span><br><span class="line">    <span class="keyword">if</span> msg.type == TEXT:</span><br><span class="line">        wx_friend.auto_reply(msg)</span><br><span class="line">    elif msg.type == RECORDING:</span><br><span class="line">        <span class="keyword">return</span> <span class="string">'不听不听，王八念经'</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        pass</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">embed()</span><br><span class="line"></span><br><span class="line"><span class="string">""</span><span class="string">"</span></span><br><span class="line"><span class="string">    免费申请图灵机器人，获取api_key</span></span><br><span class="line"><span class="string">    图灵机器人免费申请地址 http://www.tuling123.com</span></span><br><span class="line"><span class="string">"</span><span class="string">""</span></span><br><span class="line">tuling = Tuling(api_key=<span class="string">'7c8cdb56b0dc4450a8deef30a496bd4c'</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def auto_reply(msg):</span><br><span class="line">    <span class="string">""</span><span class="string">"回复消息，并返回答复文本"</span><span class="string">""</span></span><br><span class="line">    <span class="keyword">return</span> tuling.do_reply(msg)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    <span class="string">""</span><span class="string">"</span></span><br><span class="line"><span class="string">        直接点击测试图灵机器人</span></span><br><span class="line"><span class="string">        此apikey为wxpy自带apikey，有使用次数限制，建议自己免费申请一个</span></span><br><span class="line"><span class="string">        图灵机器人免费申请地址 http://www.tuling123.com</span></span><br><span class="line"><span class="string">    "</span><span class="string">""</span></span><br><span class="line">    apikey = <span class="string">'7c8cdb56b0dc4450a8deef30a496bd4c'</span></span><br><span class="line">    api_url = <span class="string">'http://www.tuling123.com/openapi/api'</span></span><br><span class="line">    data = &#123;<span class="string">'key'</span>: apikey, <span class="string">'info'</span>: <span class="string">'你好'</span>&#125;</span><br><span class="line">    req = requests.post(api_url, data=data).text</span><br><span class="line">    replys = json.loads(req)[<span class="string">'text'</span>]</span><br><span class="line">    print(replys)</span><br><span class="line">    </span><br><span class="line">    bot = Bot()</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    def auto_accept_friends(msg):</span><br><span class="line">        <span class="string">""</span><span class="string">"自动接受好友https://github.com/pig6/wxrobot/blob/master/wx_friend.py"</span><span class="string">""</span></span><br><span class="line">        # 接受好友请求</span><br><span class="line">        new_friend = msg.card.accept()</span><br><span class="line">        # 向新的好友发送消息</span><br><span class="line">        new_friend.send(<span class="string">'我已自动接受了你的好友请求'</span>)</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    def auto_reply(msg):</span><br><span class="line">        <span class="string">""</span><span class="string">"自动回复"</span><span class="string">""</span></span><br><span class="line">        # 关键字回复 or 图灵机器人回复</span><br><span class="line">        keyword_reply(msg) or tuling_reply(msg)</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    def keyword_reply(msg):</span><br><span class="line">        <span class="string">""</span><span class="string">"关键字回复"</span><span class="string">""</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">'你叫啥'</span> <span class="keyword">in</span> msg.text or <span class="string">'你叫啥名字'</span> <span class="keyword">in</span> msg.text:</span><br><span class="line">            <span class="keyword">return</span> msg.reply(<span class="string">'沃德天·维森莫·拉莫帅·帅德布耀'</span>)</span><br><span class="line">        pass</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    def tuling_reply(msg):</span><br><span class="line">        <span class="string">""</span><span class="string">"图灵机器人回复"</span><span class="string">""</span></span><br><span class="line">        tuling_robot.auto_reply(msg)</span><br></pre></td></tr></table></figure>
<h3 id="微信防撤回"><a href="#微信防撤回" class="headerlink" title="微信防撤回"></a>微信防撤回</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/usr/bin/env python3</span></span><br><span class="line"># -*- coding: utf-8 -*-</span><br><span class="line"></span><br><span class="line">__author__ = <span class="string">'jiangwenwen'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> itchat</span><br><span class="line"><span class="keyword">from</span> itchat.content <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"></span><br><span class="line">print(<span class="string">"该程序由里客云资源站开发，网址：likeyunba.com https://segmentfault.com/a/1190000018691537"</span>)</span><br><span class="line">print(<span class="string">"作者:TANKING"</span>)</span><br><span class="line">print(<span class="string">"打开程序会弹出一个二维码，微信扫码"</span>)</span><br><span class="line">print(<span class="string">"如果二维码弹不出，那就在你这个程序的同一个目录下找到QR.png双击打开扫码"</span>)</span><br><span class="line">print(<span class="string">"扫码后，出现Start auto replying就可以实时监控消息了..."</span>)</span><br><span class="line"></span><br><span class="line">msg_information = &#123;&#125;</span><br><span class="line"># 针对表情包的内容</span><br><span class="line">face_bug = None</span><br><span class="line"></span><br><span class="line">@itchat.msg_register([TEXT, PICTURE, FRIENDS, CARD, MAP, SHARING, RECORDING, ATTACHMENT, VIDEO], isFriendChat=True, isMpChat=True)</span><br><span class="line">def handle_receive_msg(msg):</span><br><span class="line">    global face_bug</span><br><span class="line">    # 接收消息的时间</span><br><span class="line">    msg_time_rec = time.strftime(<span class="string">"%Y-%m-%d %H:%M:%S"</span>, time.localtime())</span><br><span class="line">    # 在好友列表列表中查询发送信息的好友昵称</span><br><span class="line">    msg_from = itchat.search_friends(userName=msg[<span class="string">'FromUserName'</span>])[<span class="string">'NickName'</span>]</span><br><span class="line">    # 信息发送的时间</span><br><span class="line">    msg_time = msg[<span class="string">'CreateTime'</span>]</span><br><span class="line">    # 每条信息的ID</span><br><span class="line">    msg_id = msg[<span class="string">'MsgId'</span>]</span><br><span class="line">    # 储存信息的内容</span><br><span class="line">    msg_content = None</span><br><span class="line">    # 储存分享的连接，比如分享的文章和音乐</span><br><span class="line">    msg_share_url = None</span><br><span class="line"></span><br><span class="line">    # 如果发送的消息是文本或者好友推荐</span><br><span class="line">    <span class="keyword">if</span> msg[<span class="string">'Type'</span>] == <span class="string">'Text'</span> or msg[<span class="string">'Type'</span>] == <span class="string">'Friends'</span>:</span><br><span class="line">        msg_content = msg[<span class="string">'Text'</span>]</span><br><span class="line">        print(msg_content)</span><br><span class="line"></span><br><span class="line">    # 如果发送的消息是附件，视频，图片，语音</span><br><span class="line">    elif msg[<span class="string">'Type'</span>] == <span class="string">'Attachment'</span> or msg[<span class="string">'Type'</span>] == <span class="string">'Video'</span> \</span><br><span class="line">        or msg[<span class="string">'Type'</span>] == <span class="string">'Picture'</span>\</span><br><span class="line">            or msg[<span class="string">'Type'</span>] == <span class="string">'Recording'</span>:</span><br><span class="line">        # 内容为下载文件名</span><br><span class="line">        msg_content = msg[<span class="string">'FileName'</span>]</span><br><span class="line">        msg[<span class="string">'Text'</span>](str(msg_content))</span><br><span class="line"></span><br><span class="line">    # 如果消息是推荐的名片</span><br><span class="line">    elif msg[<span class="string">'Type'</span>] == <span class="string">'Card'</span>:</span><br><span class="line">        # 内容是推荐人的昵称和性别</span><br><span class="line">        msg_content = msg[<span class="string">'RecommendInfo'</span>][<span class="string">'NickName'</span>] + <span class="string">'的名片'</span></span><br><span class="line">        <span class="keyword">if</span> msg[<span class="string">'RecommendInfo'</span>][<span class="string">'Sex'</span>] == <span class="number">1</span>:</span><br><span class="line">            msg_content += <span class="string">'性别为男'</span></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            msg_content += <span class="string">'性别为女'</span></span><br><span class="line"></span><br><span class="line">        print(msg_content)</span><br><span class="line"></span><br><span class="line">    # 如果消息为分享的位置信息</span><br><span class="line">    elif msg[<span class="string">'Type'</span>] == <span class="string">'Map'</span>:</span><br><span class="line">        x, y, location = re.search(</span><br><span class="line">            <span class="string">"&lt;location x=\"(.*?)\" y=\"(.*?)\".*label=\"(.*?)\".*"</span>, msg[<span class="string">'OriContent'</span>]).group(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>)</span><br><span class="line">        <span class="keyword">if</span> location is None:</span><br><span class="line">            # 内容为详细地址</span><br><span class="line">            msg_content = r<span class="string">'纬度-&gt;'</span> + x.__str__() + <span class="string">"经度-&gt;"</span> + y.__str__()</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            msg_content = r<span class="string">""</span> + location</span><br><span class="line"></span><br><span class="line">    # 如果消息是分享的音乐或者文章，详细的内容为文章的标题或者分享的名字</span><br><span class="line">    elif msg[<span class="string">'Type'</span>] == <span class="string">'Sharing'</span>:</span><br><span class="line">        msg_content = msg[<span class="string">'Text'</span>]</span><br><span class="line">        msg_share_url = msg[<span class="string">'Url'</span>]</span><br><span class="line">        print(msg_share_url)</span><br><span class="line">    face_bug = msg_content</span><br><span class="line"></span><br><span class="line">    # 将信息存储在字典中，每一个msg_id对应一条消息</span><br><span class="line">    msg_information.update(</span><br><span class="line">        &#123;</span><br><span class="line">            msg_id: &#123;</span><br><span class="line">                <span class="string">"msg_from"</span>: msg_from, <span class="string">"msg_time"</span>: msg_time, <span class="string">"msg_time_rec"</span>: msg_time_rec,</span><br><span class="line">                <span class="string">"msg_type"</span>: msg[<span class="string">'Type'</span>],</span><br><span class="line">                <span class="string">"msg_content"</span>: msg_content, <span class="string">"msg_share_url"</span>: msg_share_url</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">#这个是用于监听是否有friend消息撤回</span><br><span class="line">@itchat.msg_register(NOTE, isFriendChat=True, isGroupChat=True, isMpChat=True)</span><br><span class="line">def information(msg):</span><br><span class="line">    # 这里如果这里的msg['Content']中包含消息撤回和id，就执行下面的语句</span><br><span class="line">    <span class="keyword">if</span> <span class="string">'撤回了一条消息'</span> <span class="keyword">in</span> msg[<span class="string">'Content'</span>]:</span><br><span class="line">        old_msg_id = re.search(<span class="string">"\&lt;msgid\&gt;(.*?)\&lt;\/msgid\&gt;"</span>, msg[<span class="string">'Content'</span>]).group(<span class="number">1</span>)</span><br><span class="line">        # 得到消息</span><br><span class="line">        old_msg = msg_information.get(old_msg_id)</span><br><span class="line">        print(old_msg)</span><br><span class="line"></span><br><span class="line">        # 如果发送的是表情</span><br><span class="line">        <span class="keyword">if</span> len(old_msg_id)&lt;<span class="number">11</span>:</span><br><span class="line">            itchat.send_file(face_bug, toUserName=<span class="string">'filehelper'</span>)</span><br><span class="line">        # 发送撤回的提示给文件助手</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            msg_body = <span class="string">"【"</span>\</span><br><span class="line">                       + old_msg.get(<span class="string">'msg_from'</span>) + <span class="string">"撤回了】\n"</span>\</span><br><span class="line">                       + old_msg.get(<span class="string">"msg_type"</span>) + <span class="string">"消息:"</span> + <span class="string">"\n"</span>\</span><br><span class="line">                       + old_msg.get(<span class="string">"msg_time_rec"</span>) + <span class="string">"\n"</span>\</span><br><span class="line">                       + r<span class="string">""</span> + old_msg.get(<span class="string">"msg_content"</span>)</span><br><span class="line"></span><br><span class="line">        # 如果分享的文件被撤回了，那么就将分享的url加在msg_body中发送给文件助手</span><br><span class="line">        <span class="keyword">if</span> old_msg[<span class="string">'msg_type'</span>] == <span class="string">"Sharing"</span>:</span><br><span class="line">            msg_body += <span class="string">"\n就是这个链接&gt;"</span> + old_msg.get(<span class="string">'msg_share_url'</span>)</span><br><span class="line"></span><br><span class="line">        # 将撤回消息发送到文件助手</span><br><span class="line">        itchat.send_msg(msg_body, toUserName=<span class="string">"filehelper"</span>)</span><br><span class="line"></span><br><span class="line">        # 有文件的话也要将文件发送回去</span><br><span class="line">        <span class="keyword">if</span> old_msg[<span class="string">"msg_type"</span>] == <span class="string">"Picture"</span>\</span><br><span class="line">                or old_msg[<span class="string">"msg_type"</span>] == <span class="string">"Recording"</span>\</span><br><span class="line">                or old_msg[<span class="string">"msg_type"</span>] == <span class="string">"Video"</span>\</span><br><span class="line">                or old_msg[<span class="string">"msg_type"</span>] == <span class="string">"Attachment"</span>:</span><br><span class="line">            file = <span class="string">"@fil@%s"</span> % (old_msg[<span class="string">'msg_content'</span>])</span><br><span class="line">            itchat.send(msg=file, toUserName=<span class="string">'filehelper'</span>)</span><br><span class="line">            os.remove(old_msg[<span class="string">'msg_content'</span>])</span><br><span class="line"></span><br><span class="line">        # 删除字典旧信息</span><br><span class="line">        msg_information.pop(old_msg_id)</span><br><span class="line"></span><br><span class="line">itchat.auto_login(hotReload=True)</span><br><span class="line">itchat.run()</span><br></pre></td></tr></table></figure>
<h3 id="自动加群"><a href="#自动加群" class="headerlink" title="自动加群"></a>自动加群</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">    #coding=utf-8</span><br><span class="line"><span class="keyword">from</span> wxpy <span class="keyword">import</span> *</span><br><span class="line">base_bot = Bot(True)</span><br><span class="line"># 查找指定群聊群聊 ， 确保扫码微信中有 “123” 这个群</span><br><span class="line">group = base_bot.groups().search(<span class="string">'123'</span>)</span><br><span class="line"># 自动接受新的好友请求</span><br><span class="line">@base_bot.register(msg_types=FRIENDS)</span><br><span class="line">def auto_accept_friends(msg):</span><br><span class="line">    <span class="keyword">if</span> <span class="string">'加好友'</span> <span class="keyword">in</span> msg.text.lower():</span><br><span class="line">        # 接受好友请求</span><br><span class="line">        new_friend = base_bot.accept_friend(msg.card)</span><br><span class="line">        # new_friend = msg.card.accept()</span><br><span class="line">        # 向新的好友发送消息</span><br><span class="line">        new_friend.send(<span class="string">'你好，我是群聊机器人，回复"入群"口令进入群聊天哦！'</span>)</span><br><span class="line"># 接收文字消息的装饰器</span><br><span class="line">@base_bot.register(msg_types=TEXT)</span><br><span class="line">def add_into_chatroom(msg):</span><br><span class="line">    # 接收进群口令</span><br><span class="line">    <span class="keyword">if</span> msg.text.lower() == <span class="string">'入群'</span>:</span><br><span class="line">        # use_invitation为True，发送群邀请，False则拉进群聊</span><br><span class="line">        group[<span class="number">0</span>].add_members(msg.sender, use_invitation=True)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        # 其他消息</span><br><span class="line">        <span class="keyword">return</span> u<span class="string">'收到：'</span> + msg.text</span><br><span class="line">base_bot.join()</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> sex, count <span class="keyword">in</span> friends_stat[<span class="string">"sex"</span>].iteritems():</span><br><span class="line">    # 1代表MALE, 2代表FEMALE</span><br><span class="line">    <span class="keyword">if</span> sex == <span class="number">1</span>:</span><br><span class="line">        print <span class="string">"MALE %d"</span> % count</span><br><span class="line">    elif sex == <span class="number">2</span>:</span><br><span class="line">        print <span class="string">"FEMALE %d"</span> % count</span><br><span class="line">        </span><br><span class="line"> <span class="keyword">from</span> wxpy <span class="keyword">import</span> *</span><br><span class="line"> </span><br><span class="line"> bot = Bot(cache_path=True)</span><br><span class="line"> friends_stat = bot.friends().stats()</span><br><span class="line"> </span><br><span class="line"> friend_loc = [] # 每一个元素是一个二元列表，分别存储地区和人数信息</span><br><span class="line"> <span class="keyword">for</span> province, count <span class="keyword">in</span> friends_stat[<span class="string">"province"</span>].iteritems():</span><br><span class="line">     <span class="keyword">if</span> province != <span class="string">""</span>: </span><br><span class="line">         friend_loc.append([province, count])</span><br><span class="line"> </span><br><span class="line"> # 对人数倒序排序</span><br><span class="line"> friend_loc.sort(key=lambda x: x[<span class="number">1</span>], reverse=True)</span><br><span class="line"> </span><br><span class="line"> # 打印人数最多的10个地区</span><br><span class="line"> <span class="keyword">for</span> item <span class="keyword">in</span> friend_loc[:<span class="number">10</span>]:</span><br><span class="line">     print item[<span class="number">0</span>], item[<span class="number">1</span>]</span><br></pre></td></tr></table></figure>
<h3 id="群发消息"><a href="#群发消息" class="headerlink" title="群发消息"></a>群发消息</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> time</span><br><span class="line"># 初始化一个机器人对象https://yfzhou.coding.me/2018/09/04/%E5%BE%AE%E4%BF%A1%E6%9C%80%E5%BC%BA%E8%8A%B1%E5%BC%8F%E6%93%8D%E4%BD%9C%EF%BC%8C%E5%B8%A6%E4%BD%A0%E7%8E%A9%E8%BD%AC-wxpy/</span><br><span class="line">#https://gitee.com/ShaErHu/wxpy_matplotlib_learning</span><br><span class="line"># cache_path为登录状态缓存路径，给定值为第一次登录生成的缓存文件路径</span><br><span class="line">bot = Bot(cache_path=<span class="string">"D:\PycharmProjects\pythonProcedure\com\zyf\weixin\wxpy.pkl"</span>)</span><br><span class="line"></span><br><span class="line"># 群发消息（谨慎使用，哈哈哈）</span><br><span class="line">my_friends = bot.friends(update=False)</span><br><span class="line">my_friends.pop(0)   # 去除列表第一个元素（自己）</span><br><span class="line">for i in range(120): # 时间限制2分钟内最多发120次（具体看wxpy官方文档异常处理）</span><br><span class="line">    friend = my_friends[i]</span><br><span class="line">    friend.send(<span class="string">'Good morning,the early bird catches the worm!(早上好，早起的鸟儿有虫吃！)'</span>)</span><br><span class="line">    time.sleep(<span class="number">2</span>)</span><br><span class="line">    friend.send(<span class="string">'不用回复，生活中一起加油！'</span>)</span><br><span class="line">    </span><br><span class="line">   </span><br><span class="line"># 获取所有好友[返回列表包含Chats对象(你的所有好友，包括自己)]</span><br><span class="line">t0 = bot.friends(update=False)</span><br><span class="line"># 查看自己好友数(除开自己)</span><br><span class="line">print(<span class="string">"我的好友数："</span>+str(len(t0)<span class="number">-1</span>))</span><br><span class="line"></span><br><span class="line"># 获取所有微信群[返回列表包含Groups对象]</span><br><span class="line">t1 = bot.groups(update=False)</span><br><span class="line"># 查看微信群数(活跃的)</span><br><span class="line">print(<span class="string">"我的微信群聊数："</span>+str(len(t1)))</span><br><span class="line"></span><br><span class="line"># 获取所有关注的微信公众号[返回列表包含Chats对象]</span><br><span class="line">t2 = bot.mps(update=False)</span><br><span class="line"># 查看关注的微信公众号数</span><br><span class="line">print(<span class="string">"我关注的微信公众号数："</span>+str(len(t2)))</span><br><span class="line"># 初始化一个机器人对象</span><br><span class="line"># cache_path缓存路径，给定值为第一次登录生成的缓存文件路径</span><br><span class="line">bot = Bot(cache_path=<span class="string">"D:\PycharmProjects\pythonProcedure\com\zyf\weixin\wxpy.pkl"</span>)</span><br><span class="line">#获取好友列表(包括自己)</span><br><span class="line">my_friends = bot.friends(update=False)</span><br><span class="line"><span class="string">''</span><span class="string">'</span></span><br><span class="line"><span class="string">stats_text 函数：帮助我们简单统计微信好友基本信息</span></span><br><span class="line"><span class="string">简单的统计结果的文本</span></span><br><span class="line"><span class="string">    :param total: 总体数量</span></span><br><span class="line"><span class="string">    :param sex: 性别分布</span></span><br><span class="line"><span class="string">    :param top_provinces: 省份分布</span></span><br><span class="line"><span class="string">    :param top_cities: 城市分布</span></span><br><span class="line"><span class="string">    :return: 统计结果文本</span></span><br><span class="line"><span class="string">'</span><span class="string">''</span></span><br><span class="line">print(my_friends.stats_text())</span><br><span class="line">bot = Bot(cache_path=<span class="string">"D:\PycharmProjects\pythonProcedure\com\zyf\weixin\wxpy.pkl"</span>)</span><br><span class="line">#获取好友列表(包括自己)</span><br><span class="line">my_friends = bot.friends(update=False)</span><br><span class="line"># 微信昵称</span><br><span class="line">nick_name = <span class="string">''</span></span><br><span class="line"># 微信个性签名</span><br><span class="line">wx_signature = <span class="string">''</span></span><br><span class="line"><span class="keyword">for</span> friend <span class="keyword">in</span> my_friends:</span><br><span class="line">    # 微信昵称：NickName</span><br><span class="line">    nick_name = nick_name + friend.raw[<span class="string">'NickName'</span>]</span><br><span class="line">    # 个性签名：Signature</span><br><span class="line">    wx_signature = wx_signature + friend.raw[<span class="string">'Signature'</span>]</span><br><span class="line"></span><br><span class="line">nick_name = jiebaclearText(nick_name)</span><br><span class="line">wx_signature = jiebaclearText(wx_signature)</span><br><span class="line">make_wordcloud(nick_name,<span class="number">1</span>)</span><br><span class="line">make_wordcloud(wx_signature,<span class="number">2</span>)</span><br><span class="line"># 获取微信公众号名称</span><br><span class="line">wx_public_name = <span class="string">''</span></span><br><span class="line"># 公众号简介</span><br><span class="line">wx_pn_signature = <span class="string">''</span></span><br><span class="line"># 获取微信公众号列表</span><br><span class="line">my_wx_pn = bot.mps(update=False)</span><br><span class="line"><span class="keyword">for</span> wx_pn <span class="keyword">in</span> my_wx_pn:</span><br><span class="line">    wx_public_name = wx_public_name + wx_pn.raw[<span class="string">'NickName'</span>]</span><br><span class="line">    wx_pn_signature = wx_pn_signature + wx_pn.raw[<span class="string">'Signature'</span>]</span><br><span class="line"></span><br><span class="line">wx_public_name = jiebaclearText(wx_public_name)</span><br><span class="line">make_wordcloud(wx_public_name,<span class="number">3</span>)</span><br><span class="line">wx_pn_signature = jiebaclearText(wx_pn_signature)</span><br><span class="line">make_wordcloud(wx_pn_signature,<span class="number">4</span>)</span><br></pre></td></tr></table></figure>
<h3 id="人脸识别"><a href="#人脸识别" class="headerlink" title="人脸识别"></a>人脸识别</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/usr/bin/env python</span></span><br><span class="line"># -*- coding: utf-8 -*-</span><br><span class="line"># @Time    : 2018/11/5 14:21</span><br><span class="line"># @Author  : yfzhou</span><br><span class="line"># @Site    : </span><br><span class="line"># @File    : face_id.py</span><br><span class="line"># @Software: PyCharm</span><br><span class="line"># Life is short, I use python.</span><br><span class="line"># 人脸识别https://yfzhou.coding.me/2018/11/12/OpenCV-Python-%E5%AE%9E%E7%8E%B0%E7%AE%80%E5%8D%95%E4%BA%BA%E8%84%B8%E8%AF%86%E5%88%AB/</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"></span><br><span class="line">filename = <span class="string">"C:\\Users\\Administrator\\Pictures\\2018-05-16\\1865.JPG"</span></span><br><span class="line"></span><br><span class="line">def detect(filename):</span><br><span class="line">    # haarcascade_frontalface_default.xml存储在package安装的位置</span><br><span class="line">    # haarcascade_frontalface_default 识别人脸</span><br><span class="line">    # haarcascade_eye 识别眼睛</span><br><span class="line">    face_cascade = cv2.CascadeClassifier(</span><br><span class="line">        <span class="string">"D:\\Python\\Python37\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml"</span>)</span><br><span class="line">    eye_cascade = cv2.CascadeClassifier(<span class="string">"D:\\Python\\Python37\\Lib\\site-packages\\cv2\\data\\haarcascade_eye.xml"</span>)</span><br><span class="line">    img = cv2.imread(filename)</span><br><span class="line">    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)</span><br><span class="line">    # 传递参数是scaleFactor和minNeighbors,分别表示人脸检测过程中每次迭代时图像的压缩率以及每个人脸矩形保留近邻数目的最小值</span><br><span class="line">    # 检测结果返回人脸矩形数组</span><br><span class="line">    faces = face_cascade.detectMultiScale(gray, <span class="number">1.1</span>, <span class="number">5</span>)</span><br><span class="line">    print(faces)</span><br><span class="line">    <span class="keyword">for</span> (x, y, w, h) <span class="keyword">in</span> faces:</span><br><span class="line">        # 给最新的检测到的人脸图片外面，标明一个方框</span><br><span class="line">        img = cv2.rectangle(img, (x, y), (x + w, y + h), (<span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>), <span class="number">3</span>)</span><br><span class="line">        face_re = img[y:y + h, <span class="attr">x</span>:x + h]</span><br><span class="line">        face_re_g = gray[y:y + h, <span class="attr">x</span>:x + h]</span><br><span class="line">        eyes = eye_cascade.detectMultiScale(face_re_g)</span><br><span class="line">        <span class="keyword">for</span> (ex, ey, ew, eh) <span class="keyword">in</span> eyes:</span><br><span class="line">            cv2.rectangle(face_re, (ex, ey), (ex + ew, ey + eh), (<span class="number">0</span>, <span class="number">255</span>, <span class="number">0</span>), <span class="number">2</span>)</span><br><span class="line"></span><br><span class="line">    # cv2.namedWindow("Human Face Result!")</span><br><span class="line">    # cv2.imshow("Human Face Result!", img)</span><br><span class="line">    # 吧识别后的图片保存至指定目录</span><br><span class="line">    cv2.imwrite(<span class="string">"C:\\Users\\Administrator\\Pictures\\2018-05-16\\Face.jpg"</span>, img)</span><br><span class="line">    # cv2.waitKey(0)</span><br><span class="line">    # cv2.destroyAllWindows()</span><br><span class="line"></span><br><span class="line">detect(filename)</span><br></pre></td></tr></table></figure>
<h3 id="图片水印"><a href="#图片水印" class="headerlink" title="图片水印"></a>图片水印</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image,ImageDraw,ImageFont</span><br><span class="line">image = Image.open(<span class="string">'wechat.png'</span>)</span><br><span class="line"># 打开等待加水印的图片</span><br><span class="line">watermark = Image.open(<span class="string">'mp.png'</span>)</span><br><span class="line"># 打开水印图片</span><br><span class="line">factor = <span class="number">1</span></span><br><span class="line"># 如果觉得水印图片太大，可以缩放，这里缩放比例为50%</span><br><span class="line">watermark = watermark.resize(</span><br><span class="line">    tuple(map(lambda x: int(x * factor), watermark.size)))</span><br><span class="line"># 缩放图片</span><br><span class="line">layer=Image.new(<span class="string">'RGBA'</span>,image.size)</span><br><span class="line"># 生成一个新的layer</span><br><span class="line">layer.paste(watermark,(image.size[<span class="number">0</span>]-watermark.size[<span class="number">0</span>],</span><br><span class="line">    image.size[<span class="number">1</span>]-watermark.size[<span class="number">1</span>]))</span><br><span class="line"># 把水印打到新的layer上去，后面参数是水印位置，此处是右下角    </span><br><span class="line">marked_img=Image.composite(layer,image,layer)</span><br><span class="line"># 添加水印</span><br><span class="line"># marked_img.show()# 打开生成的图片（缓存图片）</span><br><span class="line">marked_img.save(<span class="string">'wechat_remark.jpg'</span>)</span><br><span class="line"># 保存图片</span><br><span class="line"></span><br><span class="line">#文字水印https://www.qingwei.tech/programe-develops/python/1154.html</span><br><span class="line">image = Image.open(<span class="string">'lifeistoshort.jpg'</span>)</span><br><span class="line"># 打开要加水印的图片</span><br><span class="line">text=input(<span class="string">'输入你的水印文字:\n'</span>)</span><br><span class="line"># 提示要打水印的文字</span><br><span class="line">font=ImageFont.truetype(<span class="string">'C:\Windows\Fonts\simhei.ttf'</span>,<span class="number">64</span>)</span><br><span class="line"># 获得一个字体，你也可以自己下载相应字体，第二个值是字体大小</span><br><span class="line">layer=image.convert(<span class="string">'RGBA'</span>)</span><br><span class="line"># 将图片转换为RGBA图片</span><br><span class="line">text_overlay=Image.new(<span class="string">'RGBA'</span>,layer.size)</span><br><span class="line"># 依照目标图片大小生成一张新的图片 参数[模式,尺寸,颜色(默认为0)]</span><br><span class="line">image_draw=ImageDraw.Draw(text_overlay)</span><br><span class="line"># 画图</span><br><span class="line">text_size_x,text_size_y=image_draw.textsize(text,font=font)</span><br><span class="line"># 获得字体大小,textsize(text, font=None)</span><br><span class="line">text_xy=(layer.size[<span class="number">0</span>]-text_size_x,layer.size[<span class="number">1</span>]-text_size_y)</span><br><span class="line"># 设置文本位置 此处是右下角显示</span><br><span class="line">image_draw.text(text_xy, text, font=font, fill=(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">85</span>))</span><br><span class="line"># 设置文字，位置,字体,颜色和透明度</span><br><span class="line">marked_img=Image.alpha_composite(layer,text_overlay)</span><br><span class="line"># 将水印打到原图片上生成新的图片</span><br><span class="line">marked_img.save(<span class="string">'qingwei_after.png'</span>)</span><br><span class="line"># 保存图片</span><br><span class="line">marked_img.show()</span><br><span class="line"># 显示图片（这里是生成一个临时文件，必须关闭图片 这段py代码才算结束）</span><br></pre></td></tr></table></figure>
<h3 id="Python骚操作：微信远程控制电脑"><a href="#Python骚操作：微信远程控制电脑" class="headerlink" title="Python骚操作：微信远程控制电脑"></a>Python骚操作：微信远程控制电脑</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line">pip install opencv-python</span><br><span class="line">pip install matplotlib</span><br><span class="line"><span class="meta">#!/usr/bin/env python</span></span><br><span class="line"># -*- coding: utf-8 -*-</span><br><span class="line"># @Time    : 2018/8/20 11:12</span><br><span class="line"># @Author  : yfzhou</span><br><span class="line"># @Site    : https://yfzhou.coding.me/2018/08/20/Python%E9%AA%9A%E6%93%8D%E4%BD%9C%EF%BC%9A%E5%BE%AE%E4%BF%A1%E8%BF%9C%E7%A8%8B%E6%8E%A7%E5%88%B6%E7%94%B5%E8%84%91/</span><br><span class="line"># @File    : wechat_control_computer.py</span><br><span class="line"># @Software: PyCharm</span><br><span class="line"># Life is short, I use python.</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> itchat</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"></span><br><span class="line">sendMsg = u<span class="string">"&#123;消息助手&#125;：暂时无法回复"</span></span><br><span class="line">usageMsg = u<span class="string">"使用方法：\n1.运行CMD命令：cmd xxx (xxx为命令)\n"</span> \</span><br><span class="line">           u<span class="string">"-例如关机命令:\ncmd shutdown -s -t 0 \n"</span> \</span><br><span class="line">           u<span class="string">"2.获取当前电脑用户：cap\n3.启用消息助手(默认关闭)：ast\n"</span> \</span><br><span class="line">           u<span class="string">"4.关闭消息助手：astc"</span></span><br><span class="line">flag = 0  # 消息助手开关</span><br><span class="line">nowTime = time.localtime()</span><br><span class="line">filename = str(nowTime.tm_mday) + str(nowTime.tm_hour) + str(nowTime.tm_min) + str(nowTime.tm_sec) + <span class="string">".txt"</span></span><br><span class="line">myfile = open(filename, <span class="string">'w'</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">@itchat.msg_register(<span class="string">'Text'</span>)</span><br><span class="line">def text_reply(msg):</span><br><span class="line">    global flag</span><br><span class="line">    message = msg[<span class="string">'Text'</span>]</span><br><span class="line">    fromName = msg[<span class="string">'FromUserName'</span>]</span><br><span class="line">    toName = msg[<span class="string">'ToUserName'</span>]</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> toName == <span class="string">"filehelper"</span>:</span><br><span class="line">        <span class="keyword">if</span> message == <span class="string">"cap"</span>:</span><br><span class="line">            cap = cv2.VideoCapture(<span class="number">0</span>)</span><br><span class="line">            ret, img = cap.read()</span><br><span class="line">            cv2.imwrite(<span class="string">"weixinTemp.jpg"</span>, img)</span><br><span class="line">            itchat.send(<span class="string">'@img@%s'</span> % u<span class="string">'weixinTemp.jpg'</span>, <span class="string">'filehelper'</span>)</span><br><span class="line">            cap.release()</span><br><span class="line">        <span class="keyword">if</span> message[<span class="number">0</span>:<span class="number">3</span>] == <span class="string">"cmd"</span>:</span><br><span class="line">            os.system(message.strip(message[<span class="number">0</span>:<span class="number">4</span>]))</span><br><span class="line">        <span class="keyword">if</span> message == <span class="string">"ast"</span>:</span><br><span class="line">            flag = <span class="number">1</span></span><br><span class="line">            itchat.send(<span class="string">"消息助手已开启"</span>, <span class="string">"filehelper"</span>)</span><br><span class="line">        <span class="keyword">if</span> message == <span class="string">"astc"</span>:</span><br><span class="line">            flag = <span class="number">0</span></span><br><span class="line">            itchat.send(<span class="string">"消息助手已关闭"</span>, <span class="string">"filehelper"</span>)</span><br><span class="line">    elif flag == <span class="number">1</span>:</span><br><span class="line">        itchat.send(sendMsg, fromName)</span><br><span class="line">        myfile.write(message)</span><br><span class="line">        myfile.write(<span class="string">"\n"</span>)</span><br><span class="line">        myfile.flush()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    itchat.auto_login()</span><br><span class="line">    itchat.send(usageMsg, <span class="string">"filehelper"</span>)</span><br><span class="line">    itchat.run()</span><br></pre></td></tr></table></figure>
<h3 id="生成中文词云图"><a href="#生成中文词云图" class="headerlink" title="生成中文词云图"></a>生成中文词云图</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">pip install wordcloud</span><br><span class="line">pip install jieba</span><br><span class="line"># -*- coding: utf-8 -*-</span><br><span class="line"># @Time    : 2018/9/4 13:52</span><br><span class="line"># @Author  : yfzhou</span><br><span class="line"># @Site    : </span><br><span class="line"># @File    : demo10.py</span><br><span class="line"># @Software: PyCharm</span><br><span class="line"># Life is short, I use python.</span><br><span class="line"></span><br><span class="line"># 词云生成工具</span><br><span class="line"><span class="keyword">from</span> wordcloud <span class="keyword">import</span> WordCloud, ImageColorGenerator</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"><span class="keyword">from</span> os <span class="keyword">import</span> path</span><br><span class="line"><span class="keyword">import</span> jieba</span><br><span class="line"></span><br><span class="line"># 获取当前的项目文件加的路径</span><br><span class="line">d = path.dirname(__file__)</span><br><span class="line"># 读取一个txt文件https://yfzhou.coding.me/2018/09/04/Python-wordcloud-jieba-%E7%94%9F%E6%88%90%E4%B8%AD%E6%96%87%E8%AF%8D%E4%BA%91%E5%9B%BE/</span><br><span class="line">text = open(r<span class="string">'C:\Users\Administrator\Desktop\阿里传：这是阿里巴巴的世界美特里斯曼.txt'</span>, <span class="string">'r'</span>, encoding=<span class="string">'utf-8'</span>).read()</span><br><span class="line"># 读入背景图片</span><br><span class="line">bg_pic = plt.imread(r<span class="string">'C:\Users\Administrator\Pictures\Other\155061877268618276.jpg'</span>)</span><br><span class="line">wordlist_after_jieba = jieba.cut(text, cut_all=True)</span><br><span class="line">wl_space_split = <span class="string">" "</span>.join(wordlist_after_jieba)</span><br><span class="line"># 生成词云</span><br><span class="line">font = d + r<span class="string">'static/simkai.ttf'</span></span><br><span class="line">wc = WordCloud(</span><br><span class="line">    mask=bg_pic,</span><br><span class="line">    background_color=<span class="string">'white'</span>,</span><br><span class="line">    font_path=font,</span><br><span class="line">    scale=<span class="number">1.5</span>,</span><br><span class="line">    max_words=<span class="number">1500</span></span><br><span class="line">).generate(wl_space_split)</span><br><span class="line">image_colors = ImageColorGenerator(bg_pic)</span><br><span class="line"># 图片背景</span><br><span class="line">bg_color = ImageColorGenerator(bg_pic)</span><br><span class="line"># 开始画图</span><br><span class="line">plt.imshow(wc.recolor(color_func=bg_color))</span><br><span class="line">plt.axis(<span class="string">'off'</span>)</span><br><span class="line">plt.show()</span><br><span class="line"># 保存图片</span><br><span class="line">wc.to_file(d + r<span class="string">"/image/render_09.png"</span>)</span><br></pre></td></tr></table></figure>
<h3 id="朗读网页"><a href="#朗读网页" class="headerlink" title="朗读网页"></a>朗读网页</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">pip install readability-lxml</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">from</span> readability <span class="keyword">import</span> Document</span><br><span class="line">pip install goose3</span><br><span class="line">response = requests.get(<span class="string">'https://hoxis.github.io/run-ansible-without-specifying-the-inventory-but-the-host-directly.html'</span>)</span><br><span class="line">doc = Document(response.text)</span><br><span class="line">print(doc.title())</span><br><span class="line">#https://yfzhou.coding.me/2018/09/05/%E6%89%8B%E6%8A%8A%E6%89%8B%E6%95%99%E4%BD%A0%E7%94%A8-Python-%E6%9D%A5%E6%9C%97%E8%AF%BB%E7%BD%91%E9%A1%B5/</span><br><span class="line">&gt;&gt;&gt; <span class="keyword">from</span> goose3 <span class="keyword">import</span> Goose</span><br><span class="line">&gt;&gt;&gt; <span class="keyword">from</span> goose3.text <span class="keyword">import</span> StopWordsChinese</span><br><span class="line">&gt;&gt;&gt; url  = <span class="string">'http://news.china.com/socialgd/10000169/20180616/32537640_all.html'</span></span><br><span class="line">&gt;&gt;&gt; g = Goose(&#123;<span class="string">'stopwords_class'</span>: StopWordsChinese&#125;)</span><br><span class="line">&gt;&gt;&gt; article = g.extract(url=url)</span><br><span class="line">&gt;&gt;&gt; print(article.cleaned_text[:<span class="number">150</span>])</span><br><span class="line">北京时间<span class="number">6</span>月<span class="number">15</span>日<span class="number">23</span>:<span class="number">00</span>(圣彼得堡当地时间<span class="number">18</span>:<span class="number">00</span>)，<span class="number">2018</span>年世界杯B组一场比赛在圣彼得堡球场展开角逐，伊朗<span class="number">1</span>比<span class="number">0</span>险胜摩洛哥，伊朗前锋阿兹蒙半场结束前错过单刀机会，鲍哈杜兹第<span class="number">95</span>分钟自摆乌</span><br><span class="line">龙。这是伊朗<span class="number">20</span>年来首度在世界杯决赛圈取胜。</span><br><span class="line"></span><br><span class="line">本届世界杯，既相继出现替补便进球，贴补梅开二度以及东道主</span><br><span class="line"></span><br><span class="line">pip install playsound</span><br><span class="line">&gt; <span class="keyword">from</span> playsound <span class="keyword">import</span> playsound</span><br><span class="line">&gt;&gt;&gt; playsound(<span class="string">'/path/to/a/sound/file/you/want/to/play.mp3'</span>)</span><br><span class="line">#https://github.com/hoxis/to_voice/blob/master/page2voice.py</span><br></pre></td></tr></table></figure>
<h3 id="定时检测无响应进程并重启"><a href="#定时检测无响应进程并重启" class="headerlink" title="定时检测无响应进程并重启"></a>定时检测无响应进程并重启</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">#http://www.xetlab.com/2019/04/21/python%E7%BB%83%E6%89%8B%E8%84%9A%E6%9C%AC-%E5%AE%9A%E6%97%B6%E6%A3%80%E6%B5%8B%E6%97%A0%E5%93%8D%E5%BA%94%E8%BF%9B%E7%A8%8B%E5%B9%B6%E9%87%8D%E5%90%AF/</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> schedule</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def parse_output(output):</span><br><span class="line">    print(output)</span><br><span class="line">    pid_list = []</span><br><span class="line">    lines = output.strip().split(<span class="string">"\n"</span>)</span><br><span class="line">    <span class="keyword">if</span> len(lines) &gt; <span class="number">2</span>:</span><br><span class="line">        <span class="keyword">for</span> line <span class="keyword">in</span> lines[<span class="number">2</span>:]:</span><br><span class="line">            pid_list.append(line.split()[<span class="number">1</span>])</span><br><span class="line">    <span class="keyword">return</span> pid_list</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def list_not_response(process_name):</span><br><span class="line">    <span class="keyword">return</span> list_process(process_name, True)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def list_process(process_name, not_respond=False):</span><br><span class="line">    cmd = <span class="string">'tasklist /FI "IMAGENAME eq %s"'</span></span><br><span class="line">    <span class="keyword">if</span> not_respond:</span><br><span class="line">        cmd = cmd + <span class="string">' /FI "STATUS eq Not Responding"'</span></span><br><span class="line">    output = os.popen(cmd % process_name)</span><br><span class="line">    <span class="keyword">return</span> parse_output(output.read())</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def start_program(program):</span><br><span class="line">    os.popen(program)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def check_job():</span><br><span class="line">    process_name = <span class="string">"xx.exe"</span></span><br><span class="line">    not_respond_list = list_not_response(process_name)</span><br><span class="line">    <span class="keyword">if</span> len(not_respond_list) &lt;= <span class="number">0</span>:</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    pid_params = <span class="string">" "</span>.join([<span class="string">"/PID "</span> + pid <span class="keyword">for</span> pid <span class="keyword">in</span> not_respond_list])</span><br><span class="line">    os.popen(<span class="string">"taskkill /F "</span> + pid_params)</span><br><span class="line">    <span class="keyword">if</span> len(list_process(process_name)) &lt;= <span class="number">0</span>:</span><br><span class="line">        start_program(r<span class="string">'E:\xxx\xx.exe'</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    schedule.every(<span class="number">5</span>).seconds.do(check_job)</span><br><span class="line">    <span class="keyword">while</span> True:</span><br><span class="line">        schedule.run_pending()</span><br><span class="line">        time.sleep(<span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<h3 id="多线程PDF转Word"><a href="#多线程PDF转Word" class="headerlink" title="多线程PDF转Word"></a>多线程PDF转Word</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">from</span> configparser <span class="keyword">import</span> ConfigParser</span><br><span class="line"><span class="keyword">from</span> io <span class="keyword">import</span> StringIO</span><br><span class="line"><span class="keyword">from</span> io <span class="keyword">import</span> open</span><br><span class="line"><span class="keyword">from</span> concurrent.futures <span class="keyword">import</span> ProcessPoolExecutor</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> pdfminer.pdfinterp <span class="keyword">import</span> PDFResourceManager</span><br><span class="line"><span class="keyword">from</span> pdfminer.pdfinterp <span class="keyword">import</span> process_pdf</span><br><span class="line"><span class="keyword">from</span> pdfminer.converter <span class="keyword">import</span> TextConverter</span><br><span class="line"><span class="keyword">from</span> pdfminer.layout <span class="keyword">import</span> LAParams</span><br><span class="line"><span class="keyword">from</span> docx <span class="keyword">import</span> Document</span><br><span class="line">#https://github.com/python-fan/pdf2word/blob/master/main.py</span><br><span class="line"></span><br><span class="line">def read_from_pdf(file_path):</span><br><span class="line">    <span class="keyword">with</span> open(file_path, <span class="string">'rb'</span>) <span class="keyword">as</span> file:</span><br><span class="line">        resource_manager = PDFResourceManager()</span><br><span class="line">        return_str = StringIO()</span><br><span class="line">        lap_params = LAParams()</span><br><span class="line"></span><br><span class="line">        device = TextConverter(</span><br><span class="line">            resource_manager, return_str, laparams=lap_params)</span><br><span class="line">        process_pdf(resource_manager, device, file)</span><br><span class="line">        device.close()</span><br><span class="line"></span><br><span class="line">        content = return_str.getvalue()</span><br><span class="line">        return_str.close()</span><br><span class="line">        <span class="keyword">return</span> content</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def save_text_to_word(content, file_path):</span><br><span class="line">    doc = Document()</span><br><span class="line">    <span class="keyword">for</span> line <span class="keyword">in</span> content.split(<span class="string">'\n'</span>):</span><br><span class="line">        paragraph = doc.add_paragraph()</span><br><span class="line">        paragraph.add_run(remove_control_characters(line))</span><br><span class="line">    doc.save(file_path)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def remove_control_characters(content):</span><br><span class="line">    mpa = dict.fromkeys(range(<span class="number">32</span>))</span><br><span class="line">    <span class="keyword">return</span> content.translate(mpa)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def pdf_to_word(pdf_file_path, word_file_path):</span><br><span class="line">    content = read_from_pdf(pdf_file_path)</span><br><span class="line">    save_text_to_word(content, word_file_path)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def main():</span><br><span class="line">    config_parser = ConfigParser()</span><br><span class="line">    config_parser.read(<span class="string">'config.cfg'</span>)</span><br><span class="line">    config = config_parser[<span class="string">'default'</span>]</span><br><span class="line"></span><br><span class="line">    tasks = []</span><br><span class="line">    <span class="keyword">with</span> ProcessPoolExecutor(max_workers=int(config[<span class="string">'max_worker'</span>])) <span class="keyword">as</span> executor:</span><br><span class="line">        <span class="keyword">for</span> file <span class="keyword">in</span> os.listdir(config[<span class="string">'pdf_folder'</span>]):</span><br><span class="line">            extension_name = os.path.splitext(file)[<span class="number">1</span>]</span><br><span class="line">            <span class="keyword">if</span> extension_name != <span class="string">'.pdf'</span>:</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line">            file_name = os.path.splitext(file)[<span class="number">0</span>]</span><br><span class="line">            pdf_file = config[<span class="string">'pdf_folder'</span>] + <span class="string">'/'</span> + file</span><br><span class="line">            word_file = config[<span class="string">'word_folder'</span>] + <span class="string">'/'</span> + file_name + <span class="string">'.docx'</span></span><br><span class="line">            print(<span class="string">'正在处理: '</span>, file)</span><br><span class="line">            result = executor.submit(pdf_to_word, pdf_file, word_file)</span><br><span class="line">            tasks.append(result)</span><br><span class="line">    <span class="keyword">while</span> True:</span><br><span class="line">        exit_flag = True</span><br><span class="line">        <span class="keyword">for</span> task <span class="keyword">in</span> tasks:</span><br><span class="line">            <span class="keyword">if</span> not task.done():</span><br><span class="line">                exit_flag = False</span><br><span class="line">        <span class="keyword">if</span> exit_flag:</span><br><span class="line">            print(<span class="string">'完成'</span>)</span><br><span class="line">            exit(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>
<h3 id="自动化测试工具selenium"><a href="#自动化测试工具selenium" class="headerlink" title="自动化测试工具selenium"></a>自动化测试工具selenium</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">#http://jeffyang.top/Python/%E7%88%AC%E8%99%AB/Python%E7%88%AC%E8%99%AB%E5%B8%B8%E7%94%A8%E5%BA%93selenium%E8%AF%A6%E8%A7%A3/</span><br><span class="line"><span class="keyword">from</span> selenium <span class="keyword">import</span> webdriver</span><br><span class="line"><span class="keyword">from</span> selenium.webdriver.common.by <span class="keyword">import</span> By</span><br><span class="line"><span class="keyword">from</span> selenium.webdriver.common.keys <span class="keyword">import</span> Keys</span><br><span class="line"><span class="keyword">from</span> selenium.webdriver.support <span class="keyword">import</span> expected_conditions <span class="keyword">as</span> EC</span><br><span class="line"><span class="keyword">from</span> selenium.webdriver.support.wait <span class="keyword">import</span> WebDriverWait</span><br><span class="line"></span><br><span class="line">browser = webdriver.Chrome()</span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line">    browser.get(<span class="string">'https://www.baidu.com'</span>)</span><br><span class="line">    input = browser.find_element_by_id(<span class="string">'kw'</span>)</span><br><span class="line">    input.send_keys(<span class="string">'Python'</span>)</span><br><span class="line">    input.send_keys(Keys.ENTER)</span><br><span class="line">    wait = WebDriverWait(browser, <span class="number">10</span>)</span><br><span class="line">    wait.until(EC.presence_of_element_located((By.ID, <span class="string">'content_left'</span>)))</span><br><span class="line">    print(browser.current_url)</span><br><span class="line">    print(browser.get_cookies())</span><br><span class="line">    print(browser.page_source)</span><br><span class="line"><span class="keyword">finally</span>:</span><br><span class="line">    browser.close()</span><br></pre></td></tr></table></figure>
<h3 id="字符串模糊匹配"><a href="#字符串模糊匹配" class="headerlink" title="字符串模糊匹配"></a>字符串模糊匹配</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> fuzzywuzzy <span class="keyword">import</span> process</span><br><span class="line"></span><br><span class="line">courts = [<span class="string">'北京市第二中级人民法院'</span>,<span class="string">'北京市第三中级人民法院'</span>,<span class="string">'北京市石景山区人民法院'</span>]</span><br><span class="line"></span><br><span class="line">print(process.extractOne(<span class="string">'北京第三中院'</span>, courts)[<span class="number">0</span>])</span><br><span class="line">print(process.extractOne(<span class="string">'石景山区法院'</span>, courts)[<span class="number">0</span>])</span><br><span class="line"></span><br><span class="line">输出https:<span class="comment">//www.dust8.com/2019/04/20/fuzzywuzzy/</span></span><br><span class="line"></span><br><span class="line">北京市第三中级人民法院</span><br><span class="line">北京市石景山区人民法院</span><br></pre></td></tr></table></figure>
<h3 id="判断图片是否损坏"><a href="#判断图片是否损坏" class="headerlink" title="判断图片是否损坏"></a>判断图片是否损坏</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def is_valid_image(filename):</span><br><span class="line">    valid = True</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        Image.open(filename).load()</span><br><span class="line">    except OSError:</span><br><span class="line">        valid = False</span><br><span class="line">    <span class="keyword">return</span> valid</span><br></pre></td></tr></table></figure>
<h3 id="unicode转中文"><a href="#unicode转中文" class="headerlink" title="unicode转中文"></a>unicode转中文</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">str.encode(<span class="string">'utf-8'</span>).decode(<span class="string">'unicode-escape'</span>)</span><br><span class="line">https:<span class="comment">//tangx1.com/solved/</span></span><br></pre></td></tr></table></figure>
<h3 id="文字识别ocr"><a href="#文字识别ocr" class="headerlink" title="文字识别ocr"></a>文字识别ocr</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//默认使用eng文字库， imgName是图片的地址，result识别结果</span></span><br><span class="line">tesseract imgName result</span><br><span class="line">指定语言:</span><br><span class="line"></span><br><span class="line"><span class="comment">//指定使用简体中文</span></span><br><span class="line">tesseract -l chi_sim imgName result</span><br><span class="line"></span><br><span class="line"><span class="comment">//查看本地存在的语言库</span></span><br><span class="line">tesseract --list-langs</span><br><span class="line">指定多语言:</span><br><span class="line"></span><br><span class="line"><span class="comment">//指定多语言，用+号相连</span></span><br><span class="line">tesseract -l chi_sim+eng imgName result</span><br><span class="line">通过 pip 安装支持Python 版本的 Tesseract库</span><br><span class="line"></span><br><span class="line">pip install pytesseract</span><br><span class="line">通过Python代码的简单实现</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> pytesseract</span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"></span><br><span class="line">image = Image.open(<span class="string">'/Users/admin/Desktop/test.jpg'</span>)</span><br><span class="line">text = pytesseract.image_to_string(image)</span><br><span class="line">print text</span><br><span class="line">https:<span class="comment">//zhuanlan.zhihu.com/p/31530755</span></span><br><span class="line"></span><br><span class="line">https:<span class="comment">//sourceforge.net/projects/tesseract-ocr/</span></span><br><span class="line">https:<span class="comment">//github.com/tesseract-ocr/tesseract</span></span><br><span class="line">https:<span class="comment">//github.com/UB-Mannheim/tesseract/wiki </span></span><br><span class="line">https:<span class="comment">//digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w64-setup-v4.1.0-bibtag19.exe</span></span><br><span class="line">在windows可以通过exe安装包安装，下载地址可以从GitHub项目中的wiki找到。安装完成后记得将Tesseract 执行文件的目录加入到PATH中，方便后续调用。</span><br><span class="line">img = Image.open(<span class="string">"vm3.png"</span>);</span><br><span class="line">text = image_to_string(img,lang=<span class="string">'chi_sim'</span>)</span><br><span class="line">print(text)</span><br><span class="line">https:<span class="comment">//segmentfault.com/a/1190000015489113</span></span><br><span class="line"></span><br><span class="line">tesseract  <span class="number">520.</span>png outfile</span><br><span class="line">Tesseract Open Source OCR Engine v4<span class="number">.1</span><span class="number">.0</span>-bibtag19 <span class="keyword">with</span> Leptonica</span><br><span class="line">git clone https:<span class="comment">//github.com/tesseract-ocr/tessdata  太慢了</span></span><br><span class="line">https:<span class="comment">//github.com/tesseract-ocr/tessdata/raw/master/chi_sim.traineddata 直接下载这个文件</span></span><br><span class="line">wget -c https:<span class="comment">//github.com/tesseract-ocr/tessdata/blob/master/chi_sim.traineddata?raw=true</span></span><br><span class="line">下载好的语言包放入到安装目录中的testdata下即可。在windows系统你还需要将testdata目录也加入环境变量。</span><br><span class="line"></span><br><span class="line">tesseract test.png outfile -l chi_sim</span><br><span class="line">Tesseract Open Source OCR Engine v4<span class="number">.1</span><span class="number">.0</span>-bibtag19 <span class="keyword">with</span> Leptonica</span><br><span class="line">英文加汉子用-l eng+chi_sim</span><br><span class="line">https:<span class="comment">//betacat.online/posts/2018-01-16/chinese-text-ocr-via-python/</span></span><br><span class="line">http:<span class="comment">//qinghua.github.io/tesseract/</span></span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"><span class="keyword">import</span> pytesseract</span><br><span class="line"></span><br><span class="line">class Languages:</span><br><span class="line">    CHS = <span class="string">'chi_sim'</span></span><br><span class="line">    CHT = <span class="string">'chi_tra'</span></span><br><span class="line">    ENG = <span class="string">'eng'</span></span><br><span class="line"></span><br><span class="line">def img_to_str(image_path, lang=Languages.ENG):</span><br><span class="line">    <span class="keyword">return</span> pytesseract.image_to_string(Image.open(image_path), lang)</span><br><span class="line">  </span><br><span class="line">print(img_to_str(<span class="string">'image/test1.png'</span>, lang=Languages.CHS))</span><br><span class="line">print(img_to_str(<span class="string">'image/test2.png'</span>, lang=Languages.CHS))</span><br><span class="line">虽然tesseract不能直接处理PDF，但是借助ImageMagick和Ghostscript可以轻松地把PDF转换成图片文件：</span><br><span class="line"> </span><br><span class="line">brew install imagemagick</span><br><span class="line">brew install ghostscript</span><br><span class="line">convert -density <span class="number">100</span> -trim input.pdf output%<span class="number">04</span>d.jpg</span><br><span class="line">在线 https:<span class="comment">//gongpeione.github.io/quick-js-ocr/example/</span></span><br></pre></td></tr></table></figure>
<h3 id="pydub音频处理库"><a href="#pydub音频处理库" class="headerlink" title="pydub音频处理库"></a>pydub音频处理库</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> pydub <span class="keyword">import</span> AudioSegment</span><br><span class="line">song = AudioSegment.from_wav(<span class="string">"never_gonna_give_you_up.wav"</span>)</span><br><span class="line">song = AudioSegment.from_mp3(<span class="string">"never_gonna_give_you_up.mp3"</span>)</span><br><span class="line">ogg_version = AudioSegment.from_ogg(<span class="string">"never_gonna_give_you_up.ogg"</span>)</span><br><span class="line">flv_version = AudioSegment.from_flv(<span class="string">"never_gonna_give_you_up.flv"</span>)</span><br><span class="line">mp4_version = AudioSegment.from_file(<span class="string">"never_gonna_give_you_up.mp4"</span>, <span class="string">"mp4"</span>)</span><br><span class="line">wma_version = AudioSegment.from_file(<span class="string">"never_gonna_give_you_up.wma"</span>, <span class="string">"wma"</span>)</span><br><span class="line">aac_version = AudioSegment.from_file(<span class="string">"never_gonna_give_you_up.aiff"</span>, <span class="string">"aac"</span>)</span><br><span class="line">awesome.export(<span class="string">"mashup.mp3"</span>, format=<span class="string">"mp3"</span>)</span><br><span class="line">awesome.export(<span class="string">"mashup.mp3"</span>, format=<span class="string">"mp3"</span>, tags=&#123;<span class="string">'artist'</span>: <span class="string">'Various artists'</span>, <span class="string">'album'</span>: <span class="string">'Best of 2011'</span>, <span class="string">'comments'</span>: <span class="string">'This album is awesome!'</span>&#125;)</span><br><span class="line">awesome.export(<span class="string">"mashup.mp3"</span>, format=<span class="string">"mp3"</span>, bitrate=<span class="string">"192k"</span>)</span><br><span class="line">https:<span class="comment">//xin053.github.io/2016/11/05/pydub%E9%9F%B3%E9%A2%91%E5%A4%84%E7%90%86%E5%BA%93%E4%BD%BF%E7%94%A8%E8%AF%A6%E8%A7%A3/ 将目录下的所有mp4文件和flv文件转换为mp3</span></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> glob</span><br><span class="line"><span class="keyword">from</span> pydub <span class="keyword">import</span> AudioSegment</span><br><span class="line">video_dir = '/home/johndoe/downloaded_videos/'  # Path where the videos are located</span><br><span class="line">extension_list = (<span class="string">'*.mp4'</span>, <span class="string">'*.flv'</span>)</span><br><span class="line">os.chdir(video_dir) # change the workplace</span><br><span class="line"><span class="keyword">for</span> extension <span class="keyword">in</span> extension_list:</span><br><span class="line">    <span class="keyword">for</span> video <span class="keyword">in</span> glob.glob(extension):</span><br><span class="line">        mp3_filename = os.path.splitext(os.path.basename(video))[<span class="number">0</span>] + <span class="string">'.mp3'</span></span><br><span class="line">        AudioSegment.from_file(video).export(mp3_filename, format=<span class="string">'mp3'</span>)</span><br></pre></td></tr></table></figure>
<h3 id="dataset简易数据库"><a href="#dataset简易数据库" class="headerlink" title="dataset简易数据库"></a>dataset简易数据库</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> dataset</span><br><span class="line">db = dataset.connect(<span class="string">'sqlite:///:memory:'</span>)</span><br><span class="line">db = dataset.connect(<span class="string">'mysql://user:password@localhost/mydatabase'</span>)</span><br><span class="line"></span><br><span class="line">table = db[<span class="string">'sometable'</span>]</span><br><span class="line">table.insert(dict(name=<span class="string">'John Doe'</span>, age=<span class="number">37</span>))</span><br><span class="line">table.insert(dict(name=<span class="string">'Jane Doe'</span>, age=<span class="number">34</span>, gender=<span class="string">'female'</span>))</span><br><span class="line">john = table.find_one(name=<span class="string">'John Doe'</span>)</span><br><span class="line">OrderedDict([(<span class="string">'id'</span>, <span class="number">1</span>), (<span class="string">'name'</span>, <span class="string">'John Doe'</span>), (<span class="string">'age'</span>, <span class="number">37</span>), (<span class="string">'gender'</span>, None)])</span><br><span class="line"></span><br><span class="line">table.update(dict(name=<span class="string">'John Doe'</span>, age=<span class="number">47</span>), [<span class="string">'name'</span>])</span><br><span class="line">第二个参数相当于sql update语句中的where，用来过滤出需要更新的记录</span><br><span class="line"><span class="keyword">with</span> dataset.connect() <span class="keyword">as</span> tx:</span><br><span class="line">    tx[<span class="string">'user'</span>].insert(dict(name=<span class="string">'John Doe'</span>, age=<span class="number">46</span>, country=<span class="string">'China'</span>))</span><br><span class="line">事务操作可以简单的使用上下文管理器来实现,出现异常，将会回滚</span><br><span class="line">db = dataset.connect()</span><br><span class="line">db.begin()</span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line">    db[<span class="string">'user'</span>].insert(dict(name=<span class="string">'John Doe'</span>, age=<span class="number">46</span>, country=<span class="string">'China'</span>))</span><br><span class="line">    db.commit()</span><br><span class="line">except:</span><br><span class="line">    db.rollback()</span><br><span class="line">&gt;&gt;&gt; print(db)</span><br><span class="line">&lt;Database(sqlite:<span class="comment">///mydatabase.db)&gt;</span></span><br><span class="line">&gt;&gt;&gt; print(db.tables)</span><br><span class="line">[<span class="string">'user'</span>]</span><br><span class="line">&gt;&gt;&gt; print(db[<span class="string">'user'</span>].columns)</span><br><span class="line">[<span class="string">'id'</span>, <span class="string">'country'</span>, <span class="string">'name'</span>, <span class="string">'age'</span>, <span class="string">'gender'</span>]</span><br><span class="line">&gt;&gt;&gt; print(len(db[<span class="string">'user'</span>]))</span><br><span class="line"><span class="number">2</span></span><br><span class="line">&gt;&gt;&gt; table = db[<span class="string">'user'</span>]</span><br><span class="line">&gt;&gt;&gt; table</span><br><span class="line">&lt;Table(user)&gt;</span><br><span class="line">&gt;&gt;&gt; table.table</span><br><span class="line">Table(<span class="string">'user'</span>, MetaData(bind=Engine(sqlite:<span class="comment">///mydatabase.db)), Column('id', INTEGER(), table=&lt;user&gt;, primary_key=True, nullable=False), Column('country', TEXT(), table=&lt;user&gt;), Column('name', TEXT(), table=&lt;user&gt;), Column('age', INTEGER(), table=&lt;user&gt;), Column('gender', TEXT(), table=&lt;user&gt;), schema=None)</span></span><br><span class="line">    db[<span class="string">'user'</span>].distinct(<span class="string">'country'</span>)</span><br><span class="line"></span><br><span class="line">    table.delete(place=<span class="string">'Berlin'</span>)</span><br><span class="line">result = db.query(<span class="string">'SELECT country, COUNT(*) c FROM user GROUP BY country'</span>)</span><br><span class="line"><span class="keyword">for</span> row <span class="keyword">in</span> result:</span><br><span class="line">   print(row[<span class="string">'country'</span>], row[<span class="string">'c'</span>])</span><br><span class="line">   </span><br><span class="line">   result = db[<span class="string">'users'</span>].all()</span><br><span class="line">   dataset.freeze(result, format=<span class="string">'json'</span>, filename=<span class="string">'users.json'</span>)</span><br><span class="line">https:<span class="comment">//xin053.github.io/2016/11/08/dataset%E7%AE%80%E6%98%93%E6%95%B0%E6%8D%AE%E5%BA%93%E5%8C%85%E4%BD%BF%E7%94%A8%E8%AF%A6%E8%A7%A3/</span></span><br></pre></td></tr></table></figure>
<h3 id="Tesseract图片文字识别"><a href="#Tesseract图片文字识别" class="headerlink" title="Tesseract图片文字识别"></a>Tesseract图片文字识别</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">brew install tesseract</span><br><span class="line">https:<span class="comment">//github.com/tesseract-ocr/tesseract/wiki</span></span><br><span class="line">tesseract paper.png paper -l chi_sim</span><br><span class="line">tesseract paper.png paper -l chi_sim -c language_model_ngram_on=<span class="number">1</span></span><br><span class="line">tesseract paper.png paper -l chi_sim tess.conf</span><br><span class="line">https:<span class="comment">//tonydeng.github.io/2016/07/28/on-the-use-of-tesseract-picture-text-recognition/</span></span><br><span class="line">	</span><br><span class="line">tesseract -h</span><br><span class="line">Usage:</span><br><span class="line">  D:\Tesseract\tesseract.exe --help | --help-extra | --version</span><br><span class="line">  D:\Tesseract\tesseract.exe --list-langs</span><br><span class="line">  D:\Tesseract\tesseract.exe imagename outputbase [options...] [configfile...]</span><br><span class="line"></span><br><span class="line">OCR options:</span><br><span class="line">  -l LANG[+LANG]        Specify language(s) used <span class="keyword">for</span> OCR.</span><br><span class="line">NOTE: These options must occur before any configfile.</span><br><span class="line"></span><br><span class="line">Single options:</span><br><span class="line">  --help                Show <span class="keyword">this</span> help message.</span><br><span class="line">  --help-extra          Show extra help <span class="keyword">for</span> advanced users.</span><br><span class="line">  --version             Show version information.</span><br><span class="line">  --list-langs          List available languages <span class="keyword">for</span> tesseract engine.</span><br><span class="line">	</span><br><span class="line">tesseract <span class="number">1.</span>jpg test -l chi_sim</span><br><span class="line">-l chi_sim表示用训练的中文数据库识别图片中的文字，不带-l默认使用英文，多个语言之间使用+连接</span><br><span class="line"></span><br><span class="line">执行上面的命令以后，会在桌面生成一个test.txt文件，文件内容就是识别的文字</span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"><span class="keyword">import</span> pytesseract</span><br><span class="line">print(pytesseract.image_to_string(Image.open(r<span class="string">"C:\Users\zzx\Desktop\1.jpg"</span>)))</span><br><span class="line">print(pytesseract.image_to_string(Image.open(r<span class="string">"C:\Users\zzx\Desktop\1.jpg"</span>), lang=<span class="string">'fra'</span>))</span><br><span class="line"></span><br><span class="line">f = open(output_file_name)</span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line">    <span class="keyword">return</span> f.read().strip()</span><br><span class="line"><span class="keyword">finally</span>:</span><br><span class="line">    f.close()</span><br><span class="line">https:<span class="comment">//xin053.github.io/2016/10/28/Tesseract%E5%85%89%E5%AD%A6%E8%AF%86%E5%88%AB/</span></span><br></pre></td></tr></table></figure>
<h3 id="qrcode二维码生成库"><a href="#qrcode二维码生成库" class="headerlink" title="qrcode二维码生成库"></a>qrcode二维码生成库</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">pip install qrcode</span><br><span class="line">qr <span class="string">"Some text"</span> &gt; test.png</span><br><span class="line"><span class="keyword">import</span> qrcode</span><br><span class="line">img = qrcode.make(<span class="string">'Some data here'</span>)</span><br><span class="line">img.save(r<span class="string">"C:\Users\zzx\Desktop\test.jpg"</span>)</span><br><span class="line"><span class="keyword">import</span> qrcode</span><br><span class="line">qr = qrcode.QRCode(</span><br><span class="line">    version=<span class="number">1</span>,</span><br><span class="line">    error_correction=qrcode.constants.ERROR_CORRECT_L,</span><br><span class="line">    box_size=<span class="number">10</span>,</span><br><span class="line">    border=<span class="number">4</span>,</span><br><span class="line">)</span><br><span class="line">qr.add_data(<span class="string">'Some data'</span>)</span><br><span class="line">qr.make(fit=True)</span><br><span class="line">img = qr.make_image()</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//xin053.github.io/2016/10/28/qrcode%E4%BA%8C%E7%BB%B4%E7%A0%81%E7%94%9F%E6%88%90%E5%BA%93%E4%BD%BF%E7%94%A8%E8%AF%A6%E8%A7%A3/</span></span><br></pre></td></tr></table></figure>
<h3 id="FFMpeg合并视频"><a href="#FFMpeg合并视频" class="headerlink" title="FFMpeg合并视频"></a>FFMpeg合并视频</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ffmpeg -i <span class="string">"工程师的痛只有工程师能懂_高清-XNzE1NTk3Mzky_part1.flv"</span> -c copy -bsf:v h264_mp4toannexb -f mpegts <span class="number">1.</span>ts</span><br><span class="line">ffmpeg -i <span class="string">"工程师的痛只有工程师能懂_高清-XNzE1NTk3Mzky_part2.flv"</span> -c copy -bsf:v h264_mp4toannexb -f mpegts <span class="number">2.</span>ts</span><br><span class="line">ffmpeg -i <span class="string">"concat:1.ts|2.ts"</span> -c copy -bsf:a aac_adtstoasc <span class="string">"工程师的痛只有工程师能懂.mp4"</span></span><br></pre></td></tr></table></figure>
<h3 id="新闻网页正文通用抽取器"><a href="#新闻网页正文通用抽取器" class="headerlink" title="新闻网页正文通用抽取器"></a>新闻网页正文通用抽取器</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"># 使用 pip 安装</span><br><span class="line">pip install --upgrade git+https:<span class="comment">//github.com/kingname/GeneralNewsExtractor.git</span></span><br><span class="line"></span><br><span class="line"># 使用 pipenv 安装</span><br><span class="line">pipenv install git+https:<span class="comment">//github.com/kingname/GeneralNewsExtractor.git#egg=gne</span></span><br><span class="line">使用 GNE</span><br><span class="line">&gt;&gt;&gt; <span class="keyword">from</span> gne <span class="keyword">import</span> GeneralNewsExtractor</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; html = <span class="string">''</span><span class="string">'经过渲染的网页 HTML 代码'</span><span class="string">''</span></span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; extractor = GeneralNewsExtractor()</span><br><span class="line">&gt;&gt;&gt; result = extractor.extract(html, noise_node_list=[<span class="string">'//div[@class="comment-list"]'</span>])</span><br><span class="line">&gt;&gt;&gt; print(result)</span><br><span class="line"></span><br><span class="line">&#123;<span class="string">"title"</span>: <span class="string">"xxxx"</span>, <span class="string">"publish_time"</span>: <span class="string">"2019-09-10 11:12:13"</span>, <span class="string">"author"</span>: <span class="string">"yyy"</span>, <span class="string">"content"</span>: <span class="string">"zzzz"</span>&#125;</span><br><span class="line">在 Chrome 浏览器中打开对应页面，然后开启开发者工具 在Elements标签页定位到&lt;html&gt;标签，并右键，选择Copy-Copy OuterHTML，如下图所示</span><br></pre></td></tr></table></figure>
<h3 id="基于Pyqt5的电影天堂电影搜索工具"><a href="#基于Pyqt5的电影天堂电影搜索工具" class="headerlink" title="基于Pyqt5的电影天堂电影搜索工具"></a>基于Pyqt5的电影天堂电影搜索工具</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//github.com/lt94/MovieHeavens</span></span><br><span class="line">pip3 install pyqt5</span><br><span class="line">python3 movies.py</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//mp.weixin.qq.com/s?__biz=MzA3Nzc4MzY2NA==&amp;mid=2247485581&amp;amp;idx=1&amp;amp;sn=56825bf55a43c727b594d97ccbdbaff5&amp;source=41#wechat_redirect</span></span><br><span class="line"></span><br><span class="line">Windows下</span><br><span class="line"></span><br><span class="line"># only python3 is supported</span><br><span class="line">pip install pyinstaller</span><br><span class="line"># -w 不能省略,不然会运行过程中会控制台界面</span><br><span class="line">pyinstaller -F -w ./movies.py ./movieSource/MovieHeaven.py ./movieSource/fake_user_agent.py</span><br></pre></td></tr></table></figure>
<h3 id="安装-pyinstaller-失败"><a href="#安装-pyinstaller-失败" class="headerlink" title="安装 pyinstaller 失败"></a>安装 pyinstaller 失败</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">pip install pyinstaller</span><br><span class="line">提示失败</span><br><span class="line">pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=<span class="string">'files.pythonhosted.org'</span>, port=<span class="number">443</span>): Read timed out.</span><br><span class="line"></span><br><span class="line">把命令改为 &gt; pip install pyinstaller --timeout <span class="number">1000</span></span><br><span class="line">增加 timeout 时间，运行成功。</span><br></pre></td></tr></table></figure>
<p><a href="https://xin053.github.io/2016/10/30/Python%E5%AD%A6%E4%B9%A0%E9%87%8D%E7%82%B9%E6%91%98%E8%AE%B0/" target="_blank" rel="noopener">Python学习重点摘记</a></p>
<p><a href="https://github.com/Alfred1984/interesting-python" target="_blank" rel="noopener">有趣的Python爬虫和Python数据分析小项目</a></p>
<p><a href="https://betacat.online/posts/2018-01-16/chinese-text-ocr-via-python/" target="_blank" rel="noopener">识别图片中的文字 - Tesseract 和 百度云OCR的对比</a></p>
<p><a href="https://www.dust8.com/2017/02/16/speech-to-text-use-python/" target="_blank" rel="noopener">python来语音转文字</a></p>
<p><a href="https://github.com/Lyrichu/NetCloud" target="_blank" rel="noopener">网易云音乐综合爬虫Python库</a></p>
<p><a href="https://github.com/0xHJK/Proxies" target="_blank" rel="noopener">两分钟获得数千个有效代理</a></p>
<p><a href="http://jeffyang.top/Python/%E7%88%AC%E8%99%AB/Python%E7%88%AC%E8%99%AB%E5%B8%B8%E7%94%A8%E5%B7%A5%E5%85%B7/" target="_blank" rel="noopener">Python爬虫常用工具selenium phantomjs pyquery</a></p>
<p><a href="https://github.com/xiyouMc/ncmbot" target="_blank" rel="noopener">网易云音乐助手</a></p>
<p><a href="http://jeffyang.top/Python/Python%E5%BA%93Numpy%E4%BD%BF%E7%94%A8%E5%85%A5%E9%97%A8/" target="_blank" rel="noopener">Python库Numpy使用入门</a></p>
<p><a href="http://jeffyang.top/Python/%E7%88%AC%E8%99%AB/Python%E7%88%AC%E8%99%AB%E5%B8%B8%E7%94%A8%E5%BA%93pyquery%E8%AF%A6%E8%A7%A3/" target="_blank" rel="noopener">Python爬虫常用库pyquery详解</a></p>
<p><a href="http://jeffyang.top/Python/%E7%88%AC%E8%99%AB/Python%E7%88%AC%E8%99%AB%E5%B8%B8%E7%94%A8%E5%BA%93selenium%E8%AF%A6%E8%A7%A3/" target="_blank" rel="noopener">Python爬虫常用库selenium详解</a></p>
<p><a href="https://anjingwd.github.io/AnJingwd.github.io/2017/09/02/python%E5%AE%9E%E7%8E%B0excel%E4%BA%8C%E7%BB%B4%E8%A1%A8%E6%A0%BC%E6%A0%BC%E5%BC%8F%E5%8C%96/" target="_blank" rel="noopener">python实现excel二维表格格式化</a></p>
<p><a href="https://mp.weixin.qq.com/s/hb8dlm3Ixsn9vcDfInqAZQ" target="_blank" rel="noopener">python pandas 这些方法解决了数据清洗80%的工作量</a></p>
<p><a href="https://github.com/Ehco1996/Python-crawler" target="_blank" rel="noopener">从头开始 系统化的 学习如何写Python爬虫</a></p>
<p><a href="https://github.com/injetlee/Python" target="_blank" rel="noopener">Python脚本。模拟登录知乎， 爬虫，操作excel，微信公众号，远程开机</a></p>
<p><a href="https://github.com/wut0n9/Wechat_Stat" target="_blank" rel="noopener">统计微信朋友圈送出的赞票与得到的赞票人员比例</a></p>
<p><a href="https://github.com/TransparentLC/WechatMomentScreenshot" target="_blank" rel="noopener">朋友圈转发截图生成工具</a></p>
<p><a href="https://github.com/YanwenTao123/wechat" target="_blank" rel="noopener">爬取微信朋友圈和自己的动态,采用appiunm进行爬取</a></p>
<p><a href="https://github.com/xiefeisd/wecraw" target="_blank" rel="noopener">爬取微信朋友圈</a></p>
<p><a href="https://github.com/tangtaorong86/66bossRobot" target="_blank" rel="noopener">自动为朋友圈点赞/踩</a></p>
<p><a href="https://sika0819.top/2019/01/08/Python%E5%AE%9E%E7%8E%B0%E5%BE%AE%E4%BF%A1%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%96%97%E5%9B%BE/" target="_blank" rel="noopener">Python实现微信公众号机器人斗图</a></p>
<p><a href="https://github.com/wistbean/learn_python3_spider" target="_blank" rel="noopener">python3爬虫相关示例汇总</a></p>
<p><a href="https://www.cnblogs.com/sirkevin/p/5770681.html" target="_blank" rel="noopener">Python进行数据分析 基础系列随笔汇总</a></p>
<p><a href="https://morvanzhou.github.io/tutorials/data-manipulation/np-pd/2-2-np-array/" target="_blank" rel="noopener">Numpy 的创建 array 含b站视频</a></p>
<p><a href="https://github.com/Light-City/weixinAnalysis/blob/master/analysis.py" target="_blank" rel="noopener">微信好友分析</a></p>
<p><a href="https://github.com/binux/pyspider" target="_blank" rel="noopener">爬虫框架之pyspider</a></p>
<p><a href="https://github.com/python-fan/pdf2word" target="_blank" rel="noopener">多线程PDF转Word</a></p>
<p><a href="http://www.xetlab.com/2019/03/14/35%E5%B2%81%E7%A0%81%E5%86%9C%E7%9A%84%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E5%85%A5%E9%97%A8%E4%B9%8B%E8%B7%AF-python%E7%AF%87/" target="_blank" rel="noopener">机器学习入门之路-python篇</a></p>
<p><a href="http://www.xetlab.com/2019/03/13/%E7%94%A8python%E5%86%99%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E9%A2%84%E8%AD%A6%E6%9C%BA%E5%99%A8%E4%BA%BA%EF%BC%88%E6%94%AF%E6%8C%81%E5%BE%AE%E4%BF%A1%E5%92%8C%E9%92%89%E9%92%89%EF%BC%89/" target="_blank" rel="noopener">python写一个预警机器人支持微信和钉钉</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIxMzgyOTg1MQ==&amp;mid=2247484844&amp;idx=1&amp;sn=a10834a90625e04eeb9ad3179c1ad157&amp;chksm=97b19418a0c61d0e6f61268396649898f75a87967c68b6f3ec6b1f53629a604588c85c8517e0&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">如何自学 Python</a></p>
<p><a href="https://github.com/Snailclimb/Python" target="_blank" rel="noopener">Python学习第三方库案例总结</a></p>
<p><a href="https://github.com/shengqiangzhang/examples-of-web-crawlers" target="_blank" rel="noopener">淘宝模拟登录,淘宝商品爬虫</a></p>
<p><a href="https://inspurer.github.io/2018/12/01/Python%E5%AE%9E%E7%8E%B0%E5%BE%AE%E4%BF%A1%E8%87%AA%E5%8A%A8%E5%9B%9E%E5%A4%8D%E5%92%8C%E7%BE%A4%E8%81%8A%E5%8A%A9%E6%89%8B/" target="_blank" rel="noopener">Python 实现微信自动回复和群聊助手</a></p>
<p><a href="https://sika0819.top/2019/01/08/Python%E5%AE%9E%E7%8E%B0%E5%BE%AE%E4%BF%A1%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%96%97%E5%9B%BE/" target="_blank" rel="noopener">Python实现微信机器人斗图</a></p>
<p><a href="http://www.uml.org.cn/python/201904013.asp" target="_blank" rel="noopener">使用Python对微信好友进行数据分析</a></p>
<p><a href="https://echarts.baidu.com/echarts2/doc/example/pie1.html" target="_blank" rel="noopener">echarts demo</a></p>
<p><a href="https://github.com/houtianze/bypy" target="_blank" rel="noopener">百度云/百度网盘Python客户端</a></p>
<p><a href="https://www.playpi.org/2019020701.html" target="_blank" rel="noopener">初识 ItChat</a></p>
<p><a href="https://www.makcyun.top/Python_learning04.html" target="_blank" rel="noopener">Python 一键制作微信好友图片墙</a></p>
<p><a href="https://github.com/facert/zufang" target="_blank" rel="noopener">微信找房机器人</a></p>
<p><a href="https://www.yuque.com/lexiansheng/sectech/mabe06" target="_blank" rel="noopener">Python 微信机器人</a></p>
<p><a href="https://www.ershicimi.com/a/6273" target="_blank" rel="noopener">猪哥的Python入门教程</a></p>
<p><a href="https://github.com/pig6/wxrobot" target="_blank" rel="noopener">基于python的微信机器人</a></p>
<p><a href="https://blog.chatie.io/talk-about-wechat-robot/" target="_blank" rel="noopener">微信机器人方向的探索</a></p>
<p><a href="https://github.com/lb2281075105/Python-WeChat-ItChat" target="_blank" rel="noopener">微信机器人</a></p>
<p><a href="https://learnku.com/articles/27893#topnav" target="_blank" rel="noopener">开源海报生成器</a></p>
<p> <a href="http://www.zhuanzhi.ai/" target="_blank" rel="noopener">为人工智能从业者服务</a></p>
<p><a href="https://github.com/efonfighting/gzh-downloads" target="_blank" rel="noopener">公众号文章下载为PDF</a></p>
<p><a href="https://www.ctolib.com/geekeren-iWechat.html" target="_blank" rel="noopener">iWechat微信机器人实现了wxpy的Docker化</a></p>
<p><a href="https://yfzhou.coding.me/2018/09/06/Python%E9%AA%9A%E6%93%8D%E4%BD%9C-%E8%BF%98%E5%8E%9F%E5%B7%B2%E6%92%A4%E5%9B%9E%E7%9A%84%E5%BE%AE%E4%BF%A1%E6%B6%88%E6%81%AF/" target="_blank" rel="noopener">Python骚操作 | 还原已撤回的微信消息</a></p>
<p><a href="https://www.qingwei.tech/programe-develops/python/881.html" target="_blank" rel="noopener">Python Learning Note Day </a></p>
<p><a href="https://www.cnblogs.com/zlel/p/9267629.html" target="_blank" rel="noopener">Python-OpenCV基本操作cv2</a></p>
<p><a href="https://github.com/axiref/WechatSogou" target="_blank" rel="noopener">基于搜狗微信搜索的微信公众号爬虫接口</a></p>
<p><a href="http://1987.name/1433.html" target="_blank" rel="noopener">Zabbix + Python/Bash脚本实现使用企业微信发送监控报警</a></p>
<p><a href="https://blog.chatie.io/koa-wechaty-assistant/" target="_blank" rel="noopener">使用koa2+wechaty打造个人微信小秘书</a></p>
<p><a href="https://zhuanlan.zhihu.com/p/63079462" target="_blank" rel="noopener">创建微信机器人</a></p>
<p><a href="https://chuansongme.com/account/PythonCoder" target="_blank" rel="noopener">Python开发者</a></p>
<p><a href="https://mp.weixin.qq.com/s/WSF7UB4XnNu8Bu_GICXi0Q" target="_blank" rel="noopener"> Python 遇上你的微信好友</a></p>
<p><a href="https://github.com/coder-pig/CPWechatXposed" target="_blank" rel="noopener">Xposed Hook微信等APP</a></p>
<p><a href="https://www.jerrycoding.com/article/wechat-tool-2/" target="_blank" rel="noopener">微信消息自动回复、撤回消息监控</a></p>
<p><a href="http://www.jintiankansha.me/t/wo1bS0Bl8S" target="_blank" rel="noopener">Python查看微信共同好友</a></p>
<p><a href="https://mp.weixin.qq.com/s/nWxa5SZI9NN2aEaaSzV6XA" target="_blank" rel="noopener">Python知识圈原创文章合集</a></p>
<p><a href="https://www.pyzhishiquan.com/noodles-skrrr.html" target="_blank" rel="noopener">Python可视化分析「大碗宽面」b站弹幕和网易云音乐评论https://github.com/Brucepk/Kris-noodles</a></p>
<p><a href="https://github.com/Chion82/WeChatMomentStat" target="_blank" rel="noopener">微信朋友圈简单数据分析脚本</a></p>
<p><a href="https://github.com/wistbean/learn_python3_spider" target="_blank" rel="noopener">python3爬虫相关示例汇总</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MjM5MjAwODM4MA==&amp;mid=2650718575&amp;idx=3&amp;sn=425591808b5d11a7e4b04a0831fd3b41&amp;chksm=bea6b0bc89d139aa1b2d6c16c0144f862c41298f6ac432c115c0c2c2a2e0a8b1374e78636152&amp;scene=0&amp;xtrack=1" target="_blank" rel="noopener">5000 微信好友头像拼成一张图</a></p>
<p><a href="https://github.com/makcyun/eastmoney_spider" target="_blank" rel="noopener">爬取东方财富网上市公司的财务报表数据</a></p>
<p><a href="https://www.bilibili.com/video/av50200661/" target="_blank" rel="noopener">Python实现获取微信好友信息</a></p>
<p><a href="https://github.com/YueYongDev/ise_qr_generate" target="_blank" rel="noopener">Python制作一个实验室海报生成器</a></p>
<p><a href="https://mp.weixin.qq.com/s/mYkI4_NVOlQ3ue6O_QNZhg" target="_blank" rel="noopener">Python让你的命令行像坤坤一样会打篮球</a></p>
<p><a href="https://mp.weixin.qq.com/s/iPpRtFeafdq1rnc1ZT1aRA" target="_blank" rel="noopener">如何帮女朋友快速抢票</a></p>
<p><a href="https://juejin.im/post/5bce8201518825773605597d" target="_blank" rel="noopener">最全的网络爬虫干货总结</a></p>
<p><a href="https://github.com/imhuay/Algorithm_Interview_Notes-Chinese/blob/master/C-%E6%95%B0%E5%AD%A6/B-%E5%BE%AE%E7%A7%AF%E5%88%86%E7%9A%84%E6%9C%AC%E8%B4%A8.md" target="_blank" rel="noopener">微积分的基本直觉</a></p>
<p><a href="https://space.bilibili.com/88461692/video" target="_blank" rel="noopener">高数和线代入门教程</a></p>
<p><a href="https://www.makcyun.top/web_scraping_withpython20.html" target="_blank" rel="noopener">Python 告诉你所不知道的春晚 1983 -2018</a></p>
<p><a href="https://mp.weixin.qq.com/s/aM0JBtM_meQU_mSfSUwe6g" target="_blank" rel="noopener"> linux搭建12306刷票平台</a></p>
<p><a href="https://learnku.com/articles/22850" target="_blank" rel="noopener">PHP、Python、JavaScript 识别二维码和生成二维码解决方案</a></p>
<p><a href="https://github.com/xtyxtyx/sorry" target="_blank" rel="noopener">sorry，为所欲为</a></p>
<p><a href="https://sphard.github.io/gfw" target="_blank" rel="noopener">gfw</a></p>
<p><a href="https://mp.weixin.qq.com/s/gnrreVSQQyRsUJpGkWsxCg" target="_blank" rel="noopener">树莓派3的Python Web系统</a></p>
<p><a href="https://github.com/iDwyane/CrawlerDemo" target="_blank" rel="noopener">爬虫的Demo</a></p>
<p><a href="https://github.com/testerSunshine/12306" target="_blank" rel="noopener">12306火车票</a></p>
<p><a href="https://github.com/free-vpn/chrome" target="_blank" rel="noopener">翻墙</a></p>
<p><a href="https://github.com/v2ray/v2ray-core" target="_blank" rel="noopener">v2ray</a></p>
<p><a href="https://github.com/shadowsocksr-backup/shadowsocksr" target="_blank" rel="noopener">shadowsocksr</a></p>
<p><a href="https://github.com/shadowsocks/shadowsocks-windows" target="_blank" rel="noopener">shadowsocks-windows</a></p>
<p><a href="https://github.com/gfwlist/gfwlist" target="_blank" rel="noopener">gfwlist</a></p>
<p><a href="https://github.com/shadowsocks/shadowsocks/tree/2.9.1" target="_blank" rel="noopener">shadowsocks</a></p>
<p><a href="http://www.newbfun.com/dogmain.html" target="_blank" rel="noopener">人工智能舔狗</a></p>
<p><a href="https://github.com/ecthros/uncaptcha2" target="_blank" rel="noopener">google验证码破解</a></p>
<p><a href="https://github.com/lancopku/pkuseg-python?utm_source=gold_browser_extension" target="_blank" rel="noopener">中文分词工具</a></p>
<p><a href="https://github.com/d2l-ai/d2l-zh?utm_source=gold_browser_extension" target="_blank" rel="noopener">《动手学深度学习》</a></p>
<p><a href="https://github.com/testerSunshine/12306?utm_source=gold_browser_extension" target="_blank" rel="noopener">12306智能刷票，订票</a></p>
<p><a href="https://github.com/meolu/walle-web?utm_source=gold_browser_extension" target="_blank" rel="noopener"> 开源项目代码部署平台</a></p>
<p><a href="https://github.com/ageitgey/face_recognition?utm_source=gold_browser_extension" target="_blank" rel="noopener">人脸识别</a></p>
<p><a href="https://mp.weixin.qq.com/s/lyoadqBrOLGVugTA37MHYA" target="_blank" rel="noopener">网易云音乐可视化</a></p>
<p><a href="https://github.com/Tobby-star/music_163" target="_blank" rel="noopener">Python数据可视化：网易云音乐</a></p>
<p><a href="https://www.thiswaifudoesnotexist.net/" target="_blank" rel="noopener">AI 自动生成动漫头像的网站 </a></p>
<p><a href="https://github.com/lancopku/PKUSeg-python" target="_blank" rel="noopener">中文分词 Python 工具包</a></p>
<p><a href="https://github.com/LoadChange/amemv-crawler" target="_blank" rel="noopener">下载指定的 抖音（Douyin） 号的视频,抖音爬虫</a></p>
<p><a href="https://github.com/ashnkumar/sketch-code" target="_blank" rel="noopener">人工智能自动生成 HTML 代码，可用于生产环境 </a></p>
<p><a href="https://mp.weixin.qq.com/s/mGhgMEWfcYxS2AlF1vEOjA" target="_blank" rel="noopener">微信公众号爬虫</a></p>
<p><a href="https://github.com/kerlomz/captcha_trainer" target="_blank" rel="noopener">验证码识别</a></p>
<p><a href="https://github.com/zergtant/pytorch-handbook" target="_blank" rel="noopener">PyTorch 进行深度学习开发和研究的朋友快速入门 </a></p>
<p><a href="https://github.com/yzygithub/showImg.git" target="_blank" rel="noopener">鉴黄数据集 </a></p>
<p><a href="https://legacy.gitbook.com/book/germey/python3webspider/details" target="_blank" rel="noopener">Python3网络爬虫开发实战</a></p>
<p><a href="https://github.com/mengzxh/weixin_friend_check" target="_blank" rel="noopener">检测是否删除被微信好友删除</a></p>
<p><a href="https://mp.weixin.qq.com/s/UbPbNo-oy5Im1hpmF_Hj2g" target="_blank" rel="noopener">python微信头像</a></p>
<p><a href="https://github.com/0xR0/hediye" target="_blank" rel="noopener">Hash 生成器、离线破解工具</a></p>
<p><a href="https://github.com/versionzhang/python_12306" target="_blank" rel="noopener">Python 12306 的抢票工具 </a></p>
<p><a href="http://fanqieto.top/2018/07/10/python3%E5%85%A5%E9%97%A8%E5%AF%BC%E5%AD%A6/" target="_blank" rel="noopener">python3入门导学</a></p>
<p><a href="https://github.com/CriseLYJ/awesome-python-login-model" target="_blank" rel="noopener">python模拟登陆一些大型网站</a></p>
<p><a href="https://github.com/deepinsight/insightface" target="_blank" rel="noopener">人脸检测方案</a></p>
<p><a href="https://mp.weixin.qq.com/s/SQ_1TKxMihtiWxPqH3FoJw" target="_blank" rel="noopener">python数据之道公众号</a></p>
<p><a href="https://mp.weixin.qq.com/s/BgpGBOuqeO7KHi7otZ_Ubw" target="_blank" rel="noopener">Python爬虫登录</a></p>
<p><a href="http://www.liujiangblog.com/course/data/" target="_blank" rel="noopener">Python数据分析</a></p>
<p><a href="http://www.pythontip.com/" target="_blank" rel="noopener">Python之禅挑战</a></p>
<p><a href="https://www.restran.net/2018/05/10/tensorflow-applications/" target="_blank" rel="noopener">深度学习和 TensorFlow 的有趣应用</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/python/" rel="tag"># python</a>
          
            <a href="/tags/项目/" rel="tag"># 项目</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/12/12/有用的PHP项目收集/" rel="next" title="有用的PHP项目收集">
                <i class="fa fa-chevron-left"></i> 有用的PHP项目收集
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/12/18/有用的网站和工具/" rel="prev" title="有用的网站和工具">
                有用的网站和工具 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
          <div class="comments" id="comments">
             <div id="gitment-container"></div>
         </div>
  




        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#高效微信公众号历史文章和阅读数据爬虫"><span class="nav-number">1.</span> <span class="nav-text">高效微信公众号历史文章和阅读数据爬虫</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#编程竞赛"><span class="nav-number">2.</span> <span class="nav-text">编程竞赛</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#全网帮你抓取信息"><span class="nav-number">3.</span> <span class="nav-text">全网帮你抓取信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#二维码"><span class="nav-number">4.</span> <span class="nav-text">二维码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#本地区块链"><span class="nav-number">5.</span> <span class="nav-text">本地区块链</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#虚拟环境安装"><span class="nav-number">6.</span> <span class="nav-text">虚拟环境安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#网易云音乐下载"><span class="nav-number">7.</span> <span class="nav-text">网易云音乐下载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#股票行情"><span class="nav-number">8.</span> <span class="nav-text">股票行情</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用python生成微信好友地域分析"><span class="nav-number">9.</span> <span class="nav-text">使用python生成微信好友地域分析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#检测微信好友是否把你删除"><span class="nav-number">10.</span> <span class="nav-text">检测微信好友是否把你删除</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分析你的微信好友签名"><span class="nav-number">11.</span> <span class="nav-text">分析你的微信好友签名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#处理-Python-中的时区"><span class="nav-number">12.</span> <span class="nav-text">处理 Python 中的时区</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Python生成微信好友位置分布图"><span class="nav-number">13.</span> <span class="nav-text">Python生成微信好友位置分布图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#图灵机器人与指定的好友微信聊天"><span class="nav-number">14.</span> <span class="nav-text">图灵机器人与指定的好友微信聊天</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#图灵机器人回复微信"><span class="nav-number">15.</span> <span class="nav-text">图灵机器人回复微信</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#微信防撤回"><span class="nav-number">16.</span> <span class="nav-text">微信防撤回</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自动加群"><span class="nav-number">17.</span> <span class="nav-text">自动加群</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#群发消息"><span class="nav-number">18.</span> <span class="nav-text">群发消息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#人脸识别"><span class="nav-number">19.</span> <span class="nav-text">人脸识别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#图片水印"><span class="nav-number">20.</span> <span class="nav-text">图片水印</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Python骚操作：微信远程控制电脑"><span class="nav-number">21.</span> <span class="nav-text">Python骚操作：微信远程控制电脑</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#生成中文词云图"><span class="nav-number">22.</span> <span class="nav-text">生成中文词云图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#朗读网页"><span class="nav-number">23.</span> <span class="nav-text">朗读网页</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#定时检测无响应进程并重启"><span class="nav-number">24.</span> <span class="nav-text">定时检测无响应进程并重启</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#多线程PDF转Word"><span class="nav-number">25.</span> <span class="nav-text">多线程PDF转Word</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自动化测试工具selenium"><span class="nav-number">26.</span> <span class="nav-text">自动化测试工具selenium</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字符串模糊匹配"><span class="nav-number">27.</span> <span class="nav-text">字符串模糊匹配</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#判断图片是否损坏"><span class="nav-number">28.</span> <span class="nav-text">判断图片是否损坏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#unicode转中文"><span class="nav-number">29.</span> <span class="nav-text">unicode转中文</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#文字识别ocr"><span class="nav-number">30.</span> <span class="nav-text">文字识别ocr</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pydub音频处理库"><span class="nav-number">31.</span> <span class="nav-text">pydub音频处理库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#dataset简易数据库"><span class="nav-number">32.</span> <span class="nav-text">dataset简易数据库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Tesseract图片文字识别"><span class="nav-number">33.</span> <span class="nav-text">Tesseract图片文字识别</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#qrcode二维码生成库"><span class="nav-number">34.</span> <span class="nav-text">qrcode二维码生成库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#FFMpeg合并视频"><span class="nav-number">35.</span> <span class="nav-text">FFMpeg合并视频</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#新闻网页正文通用抽取器"><span class="nav-number">36.</span> <span class="nav-text">新闻网页正文通用抽取器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#基于Pyqt5的电影天堂电影搜索工具"><span class="nav-number">37.</span> <span class="nav-text">基于Pyqt5的电影天堂电影搜索工具</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装-pyinstaller-失败"><span class="nav-number">38.</span> <span class="nav-text">安装 pyinstaller 失败</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
